w2o*_*ves 4 html jquery jquery-jtable
加载Jtable后,会触发一个返回id的函数.我想根据此ID选择行,或者在每行中选中一个复选框.
负载工作正常,复选框显示.但是我无法处理复选框以便以编程方式选择它们.
任何帮助表示赞赏.
我的表创建代码如下:
//Table Definition
$('#dvChangeOrd').jtable({
title: 'Change Order Selection (Select all that apply to this request):',
paging: true,
pageSize: 5,
sorting: true,
defaultSorting: 'ChangeOrd ASC',
selecting: true, //Enable selecting
multiselect: true, //Allow multiple selecting
selectingCheckboxes: true, //Show checkboxes on first column
recordsLoaded: function (event, data) {
},
actions: {
listAction: 'c013.aspx/LoadLists',
},
fields: {
ChangeOrd: {
title: 'Change Order',
width: '15%',
},
Type: {
title: 'Type',
width: '25%',
},
Status: {
title: 'Status',
width: '10%',
},
ChangeDesc: {
title: 'Change Description',
width: '50%',
},
Amount: {
title: 'Amount',
width: '20%',
},
},
//Register to selectionChanged event to hanlde events
selectionChanged: function () {
},
});
Run Code Online (Sandbox Code Playgroud)
一旦加载了记录,可能在记录加载函数中,我想从服务器响应中选择id匹配的复选框,或者从服务器获取一组id的任何其他方式,然后选中与其对应的复选框.
谢谢
试试这个:
recordsLoaded: function(event, data) {
var selectedRows = data.serverResponse.selected_ids.map(function(id) {
return $('#dvChangeOrd').jtable('getRowByKey', id)[0];
});
$('#dvChangeOrd').jtable('selectRows', $(selectedRows));
}
Run Code Online (Sandbox Code Playgroud)
注意:selected_ids从服务器返回作为jTable响应的附加属性:
render json: {Result: 'OK', TotalRecordCount: all_contacts.count, Records: items, selected_ids: selected_ids}
Run Code Online (Sandbox Code Playgroud)