亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長(zhǎng)資訊網(wǎng)
    最全最豐富的資訊網(wǎng)站

    bootstrap用什么表格插件

    bootstrap可用“Bootstrap-Table”表格插件?!癇ootstrap-Table”是基于Bootstrap的jQuery表格插件,通過(guò)簡(jiǎn)單的設(shè)置,就可以擁有強(qiáng)大的單選、多選、排序、分頁(yè),以及編輯、導(dǎo)出、過(guò)濾等等的功能。

    bootstrap用什么表格插件

    本教程操作環(huán)境:Windows7系統(tǒng)、bootsrap3.3.7版、DELL G3電腦

    bootstrap可用“Bootstrap-Table”表格插件。

    Bootstrap table 是一款基于 Bootstrap 的 jQuery 表格插件,功能比較完備,能夠?qū)崿F(xiàn)數(shù)據(jù)異步獲取,編輯,排序等一系列功能,最可貴的是,只需要一些簡(jiǎn)單的配置就可以實(shí)現(xiàn)一個(gè)功能完備的在線表格。

    官網(wǎng)地址: http://bootstrap-table.wenzhixin.net.cn/zh-cn/

    Github地址: https://github.com/wenzhixin/bootstrap-table

    中文文檔:http://bootstrap-table.wenzhixin.net.cn/zh-cn/documentation/

    主要功能

    • 支持 Bootstrap 3 和 Bootstrap 2

    • 自適應(yīng)界面

    • 固定表頭

    • 非常豐富的配置參數(shù)

    • 直接通過(guò)標(biāo)簽使用

    • 顯示/隱藏列

    • 顯示/隱藏表頭

    • 通過(guò) AJAX 獲取 JSON 格式的數(shù)據(jù)

    • 支持排序

    • 格式化表格

    • 支持單選或者多選

    • 強(qiáng)大的分頁(yè)功能

    • 支持卡片視圖

    • 支持多語(yǔ)言

    • 支持插件

    優(yōu)點(diǎn)

    • 學(xué)習(xí)成本較低,配置簡(jiǎn)單,文檔齊全

    • 跟Bootstrap無(wú)縫銜接,整體風(fēng)格一致,也便于二次開發(fā)

    • 開發(fā)者活躍,Github定期維護(hù)

    Bootstrap Table的引入

    關(guān)于Bootstrap Table的引入,一般來(lái)說(shuō)還是兩種方法:

    1、直接下載源碼,添加到項(xiàng)目里面來(lái)。

    由于Bootstrap Table是Bootstrap的一個(gè)組件,所以它是依賴Bootstrap的,我們首先需要添加Bootstrap的引用。Bootstrap的包直接在 http://v3.bootcss.com/ 里面可以找到,版本已經(jīng)出來(lái)4的預(yù)覽版,但還是建議使用比較穩(wěn)定的Bootstrap3,目前最新的3.3.5。然后就是Bootstrap Table的包了,由于它是開源的,我們直接進(jìn)到它的源碼https://github.com/wenzhixin/bootstrap-table里面git下來(lái)就好了。然后把這兩個(gè)包分別加入到項(xiàng)目中。

    2、使用我們神奇的Nuget

    打開Nuget,搜索這兩個(gè)包

    bootstrap用什么表格插件

    我們直接安裝即可。

    bootstrap用什么表格插件

    而Bootstrap Table的版本竟然是0.4,這也太坑爹了。所以博主建議Bootstrap Table的包就直接在源碼里面去下載吧。Bootstrap Table最新的版本好像是1.9.0。

    代碼詳解

    當(dāng)然,組件引用進(jìn)來(lái)了,使用就簡(jiǎn)單了,只不過(guò)這里面涉及很多細(xì)節(jié)需要我們處理,具體我們待會(huì)再說(shuō),先來(lái)看看使用方法。

    1、在cshtml頁(yè)面引用相關(guān)組件,并定義好一個(gè)空的表格。

    @{     Layout = null; } <!DOCTYPE html> <html> <head>     <meta name="viewport" content="width=device-width" />     <title>BootStrap Table使用</title>     @*1、Jquery組件引用*@     <script src="~/Scripts/jquery-1.10.2.js"></script>      @*2、bootstrap組件引用*@     <script src="~/Content/bootstrap/bootstrap.js"></script>     <link href="~/Content/bootstrap/bootstrap.css" rel="stylesheet" />          @*3、bootstrap table組件以及中文包的引用*@     <script src="~/Content/bootstrap-table/bootstrap-table.js"></script>     <link href="~/Content/bootstrap-table/bootstrap-table.css" rel="stylesheet" />     <script src="~/Content/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>          @*4、頁(yè)面Js文件的引用*@     <script src="~/Scripts/Home/Index.js"></script> </head> <body>     <div class="panel-body" style="padding-bottom:0px;">         <div class="panel panel-default">             <div class="panel-heading">查詢條件</div>             <div class="panel-body">                 <form id="formSearch" class="form-horizontal">                     <div class="form-group" style="margin-top:15px">                         <label class="control-label col-sm-1" for="txt_search_departmentname">部門名稱</label>                         <div class="col-sm-3">                             <input type="text" class="form-control" id="txt_search_departmentname">                         </div>                         <label class="control-label col-sm-1" for="txt_search_statu">狀態(tài)</label>                         <div class="col-sm-3">                             <input type="text" class="form-control" id="txt_search_statu">                         </div>                         <div class="col-sm-4" style="text-align:left;">                             <button type="button" style="margin-left:50px" id="btn_query" class="btn btn-primary">查詢</button>                         </div>                     </div>                 </form>             </div>         </div>                 <div id="toolbar" class="btn-group">             <button id="btn_add" type="button" class="btn btn-default">                 <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增             </button>             <button id="btn_edit" type="button" class="btn btn-default">                 <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>修改             </button>             <button id="btn_delete" type="button" class="btn btn-default">                 <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>刪除             </button>         </div>         <table id="tb_departments"></table>     </div> </body> </html>

    引入需要的文件之后,我們最重要的就是定義一個(gè)空的table,如上的 <table id="tb_departments"></table> 。當(dāng)然Bootstrap table還提供了一種簡(jiǎn)介的用法,直接在table標(biāo)簽里面定義類似“data-…”等相關(guān)屬性,就不用再js里面注冊(cè)了,但博主覺(jué)得這種用法雖然簡(jiǎn)單,但不太靈活,遇到父子表等這些高級(jí)用法的時(shí)候就不太好處理了,所以咱們還是統(tǒng)一使用在js里面初始化的方式來(lái)使用table組件。

    2、Js初始化

    $(function () {      //1.初始化Table     var oTable = new TableInit();     oTable.Init();      //2.初始化Button的點(diǎn)擊事件     var oButtonInit = new ButtonInit();     oButtonInit.Init();  });   var TableInit = function () {     var oTableInit = new Object();     //初始化Table     oTableInit.Init = function () {         $('#tb_departments').bootstrapTable({             url: '/Home/GetDepartment',         //請(qǐng)求后臺(tái)的URL(*)             method: 'get',                      //請(qǐng)求方式(*)             toolbar: '#toolbar',                //工具按鈕用哪個(gè)容器             striped: true,                      //是否顯示行間隔色             cache: false,                       //是否使用緩存,默認(rèn)為true,所以一般情況下需要設(shè)置一下這個(gè)屬性(*)             pagination: true,                   //是否顯示分頁(yè)(*)             sortable: false,                     //是否啟用排序             sortOrder: "asc",                   //排序方式             queryParams: oTableInit.queryParams,//傳遞參數(shù)(*)             sidePagination: "server",           //分頁(yè)方式:client客戶端分頁(yè),server服務(wù)端分頁(yè)(*)             pageNumber:1,                       //初始化加載第一頁(yè),默認(rèn)第一頁(yè)             pageSize: 10,                       //每頁(yè)的記錄行數(shù)(*)             pageList: [10, 25, 50, 100],        //可供選擇的每頁(yè)的行數(shù)(*)             search: true,                       //是否顯示表格搜索,此搜索是客戶端搜索,不會(huì)進(jìn)服務(wù)端,所以,個(gè)人感覺(jué)意義不大             strictSearch: true,             showColumns: true,                  //是否顯示所有的列             showRefresh: true,                  //是否顯示刷新按鈕             minimumCountColumns: 2,             //最少允許的列數(shù)             clickToSelect: true,                //是否啟用點(diǎn)擊選中行             height: 500,                        //行高,如果沒(méi)有設(shè)置height屬性,表格自動(dòng)根據(jù)記錄條數(shù)覺(jué)得表格高度             uniqueId: "ID",                     //每一行的唯一標(biāo)識(shí),一般為主鍵列             showToggle:true,                    //是否顯示詳細(xì)視圖和列表視圖的切換按鈕             cardView: false,                    //是否顯示詳細(xì)視圖             detailView: false,                   //是否顯示父子表             columns: [{                 checkbox: true             }, {                 field: 'Name',                 title: '部門名稱'             }, {                 field: 'ParentName',                 title: '上級(jí)部門'             }, {                 field: 'Level',                 title: '部門級(jí)別'             }, {                 field: 'Desc',                 title: '描述'             }, ]         });     };      //得到查詢的參數(shù)     oTableInit.queryParams = function (params) {         var temp = {   //這里的鍵的名字和控制器的變量名必須一直,這邊改動(dòng),控制器也需要改成一樣的             limit: params.limit,   //頁(yè)面大小             offset: params.offset,  //頁(yè)碼             departmentname: $("#txt_search_departmentname").val(),             statu: $("#txt_search_statu").val()         };         return temp;     };     return oTableInit; };   var ButtonInit = function () {     var oInit = new Object();     var postdata = {};      oInit.Init = function () {         //初始化頁(yè)面上面的按鈕事件     };      return oInit; };

    表格的初始化也很簡(jiǎn)單,定義相關(guān)的參數(shù)即可。上面一些博主覺(jué)得重要的參數(shù)都加了注釋,并且初始化Table必須的幾個(gè)參數(shù)博主也用(*)做了標(biāo)記,如果你的表格也有太多的頁(yè)面需求,直接用必須的參數(shù)就能解決。同樣,在columns參數(shù)里面其實(shí)也有很多的參數(shù)需要設(shè)置,比如列的排序,對(duì)齊,寬度等等。這些博主覺(jué)得比較簡(jiǎn)單,不會(huì)涉及表格的功能,看看API就能搞定。

    3、在Controller里面對(duì)應(yīng)的方法

    public JsonResult GetDepartment(int limit, int offset, string departmentname, string statu)         {             var lstRes = new List<Department>();             for (var i = 0; i < 50; i++)             {                 var oModel = new Department();                 oModel.ID = Guid.NewGuid().ToString();                 oModel.Name = "銷售部" + i ;                 oModel.Level = i.ToString();                 oModel.Desc = "暫無(wú)描述信息";                 lstRes.Add(oModel);             }              var total = lstRes.Count;             var rows = lstRes.Skip(offset).Take(limit).ToList();             return Json(new { total = total, rows = rows }, JsonRequestBehavior.AllowGet);         }

    這里有一點(diǎn)需要注意:如果是服務(wù)端分頁(yè),返回的結(jié)果必須包含total、rows兩個(gè)參數(shù)。漏寫或錯(cuò)寫都會(huì)導(dǎo)致表格無(wú)法顯示數(shù)據(jù)。相反,如果是客戶端分頁(yè),這里要返回一個(gè)集合對(duì)象到前端。

    4、效果及說(shuō)明

    bootstrap用什么表格插件

    還是貼幾張效果圖出來(lái):

    bootstrap用什么表格插件

    bootstrap用什么表格插件

    bootstrap用什么表格插件

    bootstrap用什么表格插件

    推薦學(xué)習(xí):《bootstrap使用教程》

    贊(0)
    分享到: 更多 (0)
    網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)