溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

BootStrap Table 后臺數(shù)據(jù)綁定、特殊列處理、排序功能

發(fā)布時間:2020-09-20 18:53:05 來源:腳本之家 閱讀:195 作者:meetweb 欄目:web開發(fā)

本節(jié)主要介紹Bootstrap的后臺數(shù)據(jù)綁定、特殊列處理及列的排序功能

1.數(shù)據(jù)綁定

 一般做程序設計,很少是使用json文件直接綁定數(shù)據(jù)。基本上我們都是使用編程語言進行數(shù)據(jù)獲取,并做數(shù)據(jù)綁定。

放置一個Table控件

<table id="table" ></table>

調(diào)用javascript的代碼

<script >
$('#table').bootstrapTable({
  url: 'tablejson.jsp',  //數(shù)據(jù)綁定,后臺的數(shù)據(jù)從jsp代碼
  search:true,      
  uniqueId:"Id",
  pageSize:"5",
  pageNumber:"1",
  sidePagination:"client",
  pagination:true,
  height:'400',
  columns: [
  {
    field: 'Id',
    title: '中文'
  }, {
    field: 'Name',
    title: 'Name'
  }
  , {
    field: 'Desc',
    title: 'Desc'
  }
  ],
});

2.特殊列處理

 在實際應用中,我們需要增加我們的特殊列,例如是操作列,看下列的js代碼 增加了一個特殊列

{
    field: '#',
    title: 'control',formatter:function(value,row,index){
    var del='<a href="Delete!delete.action?Id='+row.Id+'" rel="external nofollow" rel="external nofollow" >刪除</a>';
    var updt='<a href="supdate.jsp?Id='+row.Id+'" rel="external nofollow" rel="external nofollow" >修改</a>';
    var add='<a href="Include.jsp?Id='+row.Id+'" rel="external nofollow" rel="external nofollow" >增加</a>'
    return del+" "+updt+"&nbsp"+add;
    }
  } 

js的代碼修改為

<script >
$('#table').bootstrapTable({
  url: 'tablejson.jsp',  //數(shù)據(jù)綁定,后臺的數(shù)據(jù)從jsp代碼
  search:true,      
  uniqueId:"Id",
  pageSize:"5",
  pageNumber:"1",
  sidePagination:"client",
  pagination:true,
  height:'400',
  columns: [
   
  {
    field: 'Id',
    title: '中文'
  }, {
    field: 'Name',
    title: 'Name'
  }
  , {
    field: 'Desc',
    title: 'Desc'
  }
,
{
    field: '#',
    title: 'control',formatter:function(value,row,index){
    var del='<a href="Delete!delete.action?Id='+row.Id+'" rel="external nofollow" rel="external nofollow" >刪除</a>';
    var updt='<a href="supdate.jsp?Id='+row.Id+'" rel="external nofollow" rel="external nofollow" >修改</a>';
    var add='<a href="Include.jsp?Id='+row.Id+'" rel="external nofollow" rel="external nofollow" >增加</a>'
    return del+" "+updt+"&nbsp"+add;
    }
  }
], }); 

3.列的排序,排序主要是在列中增加了一個屬性

{
    field: 'Name',
    title: 'Name',<br><em id="__mceDel">sortable:true</em>
}

以上所述是小編給大家介紹的BootStrap Table 后臺數(shù)據(jù)綁定、特殊列處理、排序功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對億速云網(wǎng)站的支持!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI