2014-01-14 23 views
4

加載我的Jtable後,會觸發一個返回ID的函數。我想根據這個ID選擇行或者在每一行中選中一個複選框。Jtable在加載後選擇行

負載正常工作,複選框顯示。但是,我無法獲得複選框的處理,以編程方式選擇它們。

任何幫助表示讚賞。

代碼爲我創建表是這樣的:

 //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

對於[示例](http:// stackoverf low.com/a/4528604/230513)。 – trashgod

+0

我道歉,這個問題是關於jQuery的Jtable。我已經更新了標籤。感謝您的幫助。 – w2olves

+0

你可以添加你的jtable的代碼和你觸發的函數嗎? –

回答

6

試試這個:

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

我用它在這樣

rowInserted: function (event, data) 
{ 
    if (data.record.CategoryId == $('#UnitOfMeasureId').val()) 
    { 
     data.row.addClass('jtable-row-selected'); 
    } 
}