1. 程式人生 > >BootStrap-table 複選框預設選中(checkbox)

BootStrap-table 複選框預設選中(checkbox)

BootStrap-table 複選框預設選中(checkbox)
bootstrap table colums 寫法
var columns = [{
            field : 'checked',
            checkbox : true,
            formatter : stateFormatter

        }]
2.表單值轉化
  如傳過來的值 1換為 “正常”  2換為“錯誤”



在filed 那裡新增函式  轉換就行   row 代表該行的資料

formatter: function(value,row,index){

                    if
(row.status=="1") { return"正常"; }elseif (row.status=="2") { return"凍結"; } } 用colums 屬性設定 顯示的格式 /** * 複選按鈕預設選中 格式化 * * @param
{} * value * @param {} * row * @param {} * index * @return {} */
function stateFormatter(value, row, index) { if (row.state == true) return { disabled : true,//設定是否可用 checked : true//設定選中 }; return value; } 總結 可以看出bootstrap checkbox 返回是這樣的一個結果物件{ disabled : true
,//設定是否可用 checked : true//設定選中 }; 但是 在通過bootstrap $('#Table') .bootstrapTable('getAllSelections') 獲取選中的行時候 仍然可以獲得到預設載入時選中的資料