加载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 () {
},
});
一旦加载了记录,可能在记录加载函数中,我想从服务器响应中选择id匹配的复选框,或者从服务器获取一组id的任何其他方式,然后选中对应于的复选框。它
谢谢
答案 0 :(得分:7)
试试这个:
recordsLoaded: function(event, data) {
var selectedRows = data.serverResponse.selected_ids.map(function(id) {
return $('#dvChangeOrd').jtable('getRowByKey', id)[0];
});
$('#dvChangeOrd').jtable('selectRows', $(selectedRows));
}
注意:selected_ids从服务器返回作为jTable响应的附加属性:
render json: {Result: 'OK', TotalRecordCount: all_contacts.count, Records: items, selected_ids: selected_ids}
答案 1 :(得分:1)
我以这种方式使用它
rowInserted: function (event, data)
{
if (data.record.CategoryId == $('#UnitOfMeasureId').val())
{
data.row.addClass('jtable-row-selected');
}
}