BootStrap Table 后臺數(shù)據(jù)綁定、特殊列處理、排序功能
更新時間:2017年05月27日 09:49:45 作者:meetweb
本節(jié)主要介紹Bootstrap的后臺數(shù)據(jù)綁定、特殊列處理及列的排序功能,代碼簡單易懂,非常不錯,具有參考借鑒價值,需要的的朋友參考下吧
本節(jié)主要介紹Bootstrap的后臺數(shù)據(jù)綁定、特殊列處理及列的排序功能
1.數(shù)據(jù)綁定
一般做程序設計,很少是使用json文件直接綁定數(shù)據(jù)。基本上我們都是使用編程語言進行數(shù)據(jù)獲取,并做數(shù)據(jù)綁定。
放置一個Table控件
<table id="table" ></table>
調用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+" "+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+" "+add;
}
}
], });
3.列的排序,排序主要是在列中增加了一個屬性
{
field: 'Name',
title: 'Name',<br><em id="__mceDel">sortable:true</em>
}
以上所述是小編給大家介紹的BootStrap Table 后臺數(shù)據(jù)綁定、特殊列處理、排序功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

