// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'weigh',
sortOrder: 'desc',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'name', title: __('Name'), operate: 'LIKE'},
{field: 'major_code', title: __('Major_code'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
// {field: 'pid', title: __('Pid')},
// {field: 'level_id', title: __('Level_id')},
{field: 'level.level_name', title: __('Level.level_name'), operate: false, table: table, class: 'autocontent'},
{field: 'grade', title: __('Grade'), operate: false, searchList: {"1":__('Grade 1'),"2":__('Grade 2'),"3":__('Grade 3')}, formatter: Table.api.formatter.normal},
// {field: 'weigh', title: __('权重'), operate: false, },
//排序自定义输入框
{field: 'weigh', title: __('权重'),width: 80,operate: false,formatter: Controller.api.formatter.input,events: {".text-weigh": function (e) {
e.preventDefault();
e.stopPropagation();
return false;
}}},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
// 如果字段变化,改此处的weigh即可
table.closest('.bootstrap-table').on("change", ".text-weigh", function () {
$(this).data("params", {weigh: $(this).val()});
Table.api.multi('', [$(this).data("id")], table, this);
return false;
});
// 为表格绑定事件
Table.api.bindevent(table);
table.off('dbl-click-row.bs.table');
api: {
formatter: {
input: function (value, row, index) {
value = value == null || value.length === 0 ? '' : value.toString();
return '<input type="text" class="form-control input-sm text-weigh" data-id="' + row.id + '" value="' + value + '">';
},
},
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}