本篇文章給大家分享的是有關(guān)如何在bootstrap中使用table表格,小編覺得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來(lái)看看吧。
創(chuàng)新互聯(lián)建站是一家專注于網(wǎng)站建設(shè)、做網(wǎng)站與策劃設(shè)計(jì),鹿泉網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)建站做網(wǎng)站,專注于網(wǎng)站建設(shè)10年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:鹿泉等地區(qū)。鹿泉做網(wǎng)站價(jià)格咨詢:028-86922220
1.進(jìn)入頁(yè)面,根據(jù)指定的URL加載數(shù)據(jù)(json格式)
2.加載成功,根據(jù)$table.bootstrapTable({options})顯示表格樣式。
感覺還是挺漂亮的哈,OK,下面貼代碼解釋功能。
開始之前,當(dāng)然要引用js啦
<link href="~/Content/bootstrap.min.css" rel="stylesheet" /> <link href="~/Content/bootstrap-theme.min.css" rel="stylesheet" /> <link href="~/Content/bootstrap-table/bootstrap-table.min.css" rel="stylesheet" /> <script src="~/Scripts/jquery-1.9.1.js"></script> <script src="~/Scripts/bootstrap.min.js"></script> <script src="~/Content/bootstrap-table/bootstrap-table.min.js"></script>
html代碼,一是指定table要使用的工具欄,而是寫一個(gè)空的table
<div class="row"> <div class="col-md-12"> <div class="btn-group" id="toobar" role="group" aria-label="..."> <button type="button" class="btn btn-default"> <span class="glyphicon glyphicon-plus"></span>新增 </button> <button type="button" class="btn btn-default"> <span class="glyphicon glyphicon-edit"></span>修改 </button> <button type="button" class="btn btn-default"> <span class="glyphicon glyphicon-remove"></span>刪除 </button> </div> <table id="myTable"></table> </div> </div>
js代碼,使用("#table").bootstraptable({options})填充table
$("#myTable").bootstrapTable({ url: '/BootstrapTable/GetTestData', method: 'get', toolbar: '#toobar',//工具列 striped: true,//隔行換色 cache: false,//禁用緩存 pagination: true,//啟動(dòng)分頁(yè) sidePagination: 'client',//分頁(yè)方式 pageNumber: 1,//初始化table時(shí)顯示的頁(yè)碼 pageSize: 10,//每頁(yè)條目 showFooter: false,//是否顯示列腳 showPaginationSwitch: true,//是否顯示 數(shù)據(jù)條數(shù)選擇框 sortable: false,//排序 search: true,//啟用搜索 showColumns: true,//是否顯示 內(nèi)容列下拉框 showRefresh: true,//顯示刷新按鈕 idField: 'SystemCode',//key值欄位 clickToSelect: true,//點(diǎn)擊選中checkbox singleSelect: true,//啟用單行選中 columns: [{ checkbox: true }, { field: 'SystemCode', title: '系統(tǒng)代碼', titleTooltip: 'young for you' }, { field: 'SystemDesc', title: '系統(tǒng)名稱' }, { field: 'Isvalid', title: '是否有效' }, { field: 'UUser', title: '更新人' }, { field: 'UDate', title: '更新時(shí)間' }], onClickCell: function (field, value, row, $element) { //alert(row.SystemDesc); } });
其中URL是table 數(shù)據(jù)源地址,如果table啟動(dòng)了分頁(yè)功能,后臺(tái)取數(shù)據(jù)的方法要加上limit、offset兩個(gè)int類型的參數(shù),這里把后臺(tái)代碼也貼一下。
public JsonResult GetTestData(int limit, int offset) { BugzillaModelContainer db = new BugzillaModelContainer(); List<B_SystemInfo> systemInfo = db.B_SystemInfo.ToList(); for (int i = 0; i < 20; i++) { B_SystemInfo tempSystem = new B_SystemInfo(); tempSystem.SystemCode = (i + 1).ToString(); tempSystem.SystemDesc = "測(cè)試系統(tǒng)" + (i + 1).ToString(); tempSystem.Isvalid = "Y"; tempSystem.UUser = "result_for" + (i + 1).ToString(); tempSystem.UDate = System.DateTime.Now.ToShortDateString(); systemInfo.Add(tempSystem); } var total = systemInfo.Count(); var rows = systemInfo.Skip(offset).Take(limit).ToList(); return Json(systemInfo, JsonRequestBehavior.AllowGet); }
offset表示從多少條數(shù)據(jù)開始取,limit表示取多少條數(shù)據(jù)。
客戶端搜索只要設(shè)置search=true即可。
服務(wù)端搜索,需要設(shè)置參數(shù)。
首先設(shè)置
("#table").bootstraptable({queryParams: oTableInit.queryParams}),//傳遞參數(shù)(*)
然后獲取查詢的參數(shù)
//得到查詢的參數(shù) oTableInit.queryParams = function (params) { var temp = { //這里的鍵的名字和控制器的變量名必須一直,這邊改動(dòng),控制器也需要改成一樣的 limit: params.limit, //頁(yè)面大小 offset: params.offset, //頁(yè)碼 systemcode: $("#systemcode").val(), }; return temp; };
通過button事件刷新table,重新獲取數(shù)據(jù)源,即可。
$("#btnQuery").click(function () { $table.bootstrapTable('refresh'); });
最后貼上全部html代碼~
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>Index</title> <link href="~/Content/bootstrap.min.css" rel="external nofollow" rel="stylesheet" /> <link href="~/Content/bootstrap-theme.min.css" rel="external nofollow" rel="stylesheet" /> <link href="~/Content/bootstrap-table/bootstrap-table.min.css" rel="external nofollow" rel="stylesheet" /> <script src="~/Scripts/jquery-1.9.1.js"></script> <script src="~/Scripts/bootstrap.min.js"></script> <script src="~/Content/bootstrap-table/bootstrap-table.min.js"></script> </head> <body> <div class="container"> <div class="row"> <div class="col-md-8"> </div> </div> <div class="row"> <div class="col-md-12"> <div class="btn-group" id="toobar" role="group" aria-label="..."> <button type="button" class="btn btn-default"> <span class="glyphicon glyphicon-plus"></span>新增 </button> <button type="button" class="btn btn-default"> <span class="glyphicon glyphicon-edit"></span>修改 </button> <button type="button" class="btn btn-default"> <span class="glyphicon glyphicon-remove"></span>刪除 </button> </div> <table id="myTable"></table> </div> </div> </div> <script> $(function () { var itable = TableInit(); itable.Init(); }); var TableInit = function () { var myTableInit = new Object(); myTableInit.Init = function () { $("#myTable").bootstrapTable({ url: '/BootstrapTable/GetTestData', method: 'get', toolbar: '#toobar',//工具列 striped: true,//隔行換色 cache: false,//禁用緩存 pagination: true,//啟動(dòng)分頁(yè) sidePagination: 'client',//分頁(yè)方式 pageNumber: 1,//初始化table時(shí)顯示的頁(yè)碼 pageSize: 10,//每頁(yè)條目 showFooter: false,//是否顯示列腳 showPaginationSwitch: true,//是否顯示 數(shù)據(jù)條數(shù)選擇框 sortable: false,//排序 search: true,//啟用搜索 showColumns: true,//是否顯示 內(nèi)容列下拉框 showRefresh: true,//顯示刷新按鈕 idField: 'SystemCode',//key值欄位 clickToSelect: true,//點(diǎn)擊選中checkbox singleSelect: true,//啟用單行選中 columns: [{ checkbox: true }, { field: 'SystemCode', title: '系統(tǒng)代碼', titleTooltip: 'young for you' }, { field: 'SystemDesc', title: '系統(tǒng)名稱' }, { field: 'Isvalid', title: '是否有效' }, { field: 'UUser', title: '更新人' }, { field: 'UDate', title: '更新時(shí)間' }], onClickCell: function (field, value, row, $element) { //alert(row.SystemDesc); } }); }; return myTableInit; }; </script> </body> </html>
以上就是如何在bootstrap中使用table表格,小編相信有部分知識(shí)點(diǎn)可能是我們?nèi)粘9ぷ鲿?huì)見到或用到的。希望你能通過這篇文章學(xué)到更多知識(shí)。更多詳情敬請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
文章名稱:如何在bootstrap中使用table表格
網(wǎng)頁(yè)路徑:http://chinadenli.net/article32/gohopc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、營(yíng)銷型網(wǎng)站建設(shè)、網(wǎng)站策劃、云服務(wù)器、網(wǎng)頁(yè)設(shè)計(jì)公司、品牌網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)