function listEditor(data,productCode) { $('#tab1').bootstrapTable('load', data); $('#tab1').bootstrapTable({ method:'POST', dataType:'json', contentType: "application/x-www-form-urlencoded", cache: false, striped: true, //是否顯示行間隔色 sidePagination: "client", //分頁方式:client客戶端分頁,server服務端分頁(*) showColumns:true, pagination:true, minimumCountColumns:2, search: true, pageNumber:1, //初始化加載第一頁,默認第一頁 pageSize: 10, //每頁的記錄行數(*) idField: "productCode", pageList: [10, 15, 20, 25], //可供選擇的每頁的行數(*) uniqueId: "id", //每一行的唯一標識,一般為主鍵列 showExport: true, singleSelect : true, // 單選checkbox onEditableSave: function (field, row, oldValue, $el) { $.ajax({ success: function (data, status) { console.log(row); if (status == "success") { layer.msg("編輯成功", {icon: 7}); } }, error: function () { layer.msg("Error", {icon: 7}); }, complete: function () { } }); }, data: data, columns: [{ field : 'state', checkbox:true, formatter : stateFormatter }, { field:'rowId', title:'序號', width:30, align: 'center', formatter:function(value,row,index){ row.rowId = index; return index+1; }}, { field: 'productCode', title: '產品編碼' }, { field: 'productName', title: '產品名稱' }, { field: 'markingPrice', title: '活動價格(¥)', editable: { type: 'text', validate: function (v) { if ($.trim(v) == '') { return '活動價格不能為空!'; } if (isNaN(v)) { return '活動價格必須是數字'; } var reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/; if(!reg.test(v)) { return '請輸入正確的價格'; } } }, }] }); }
//對應的函數進行判斷; function stateFormatter(value, row, index) { if (row.state == true) return { disabled : false,//設置是否可用 checked : true//設置選中 }; return value; }