DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> 淺析Bootstrap表格的使用
淺析Bootstrap表格的使用
編輯:關於JavaScript     

Bootstrap - 簡潔、直觀、強悍、移動設備優先的前端開發框架,讓web開發更迅速、簡單。下面給大家介紹Bootstrap表格的使用,一起學習吧。

先定義前端table

<table class="table table-striped table-bordered table-hover" id="expandabledatatable"></table> 

然後是JS

/*
* 初始化表格
*/
var oTable = $('#expandabledatatable').dataTable({
"sDom": "Tflt<'row DTTTFooter'<'col-sm-6'i><'col-sm-6'p>>",
"aoColumnDefs": [
{
"bSortable": false, "aTargets": [0],
"render": function (data, type, full) {
return '<i class="fa fa-plus-square-o row-details"></i>';
}
},
{ "aTargets": [1], "data": "TaskName", "title": "任務名稱" },
{ "aTargets": [2], "data": "CronExpression", "title": "表達式" },
{ "aTargets": [3], "data": "Remark", "title": "說明" },
{
"bSortable": false, "aTargets": [4], "title": "運行狀態",
"render": function (data, type, full) {
if (full["Enabled"]==true){
return '<button type="button" class="btn btn-success btn-sm">運行</button>';
}
else {
return '<button type="button" class="btn btn-warning btn-sm">停止</button>';
}
}
},
{
"bSortable": false, "aTargets": [5],
"render": function (data, type, full) {
return '<a href="#" class="btn btn-info btn-xs edit"><i class="fa fa-edit"></i> 編輯</a> <a href="#" class="btn btn-danger btn-xs delete"><i class="fa fa-trash-o"></i> 刪除</a>';
}
}
],
"bServerSide": true,
"sAjaxSource": "/Task/GetAllTask",
"aaSorting": [[1, 'asc']],
"aLengthMenu": [
[5, 15, 20, -1],
[5, 15, 20, "All"]
],
"iDisplayLength": 5,
"searching": false,
"bLengthChange": false,
"language": {
"sProcessing": "正在加載數據...",
"sInfoEmpty": "記錄數為0",
"sInfoFiltered": " 從 _MAX_ 條過濾",
"sZeroRecords": "沒有您要搜索的內容",
"search": "",
"sLengthMenu": "_MENU_",
"sInfo": "從 _START_ 到 _END_ /共 _TOTAL_ 條數據",
"oPaginate": {
"sPrevious": "上一頁",
"sNext": "下一頁",
}
},
"fnServerData": function (sSource, aoData, fnCallback) {
$.ajax({
"type": 'post',
"url": sSource,
"dataType": "json",
"data": {
aoData: JSON.stringify(aoData)
},
"success": function (resp) {
fnCallback(resp);
}
});
}
}); 

該表格的數據是從服務器端取得,所以必須配置下面這些屬性,否則無法從服務器端獲得數據

"bServerSide": true,
"sAjaxSource": "/Task/GetAllTask",
"fnServerData": function (sSource, aoData, fnCallback) {
$.ajax({
"type": 'post',
"url": sSource,
"dataType": "json",
"data": {
aoData: JSON.stringify(aoData)
},
"success": function (resp) {
fnCallback(resp);
}
});
}

以上所述是小編給大家介紹的Bootstrap表格的使用的相關知識,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對網站的支持!

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved