【问题标题】:Jtable Select Rows after Load加载后 Jtable 选择行
【发布时间】:2014-01-14 16:55:42
【问题描述】:

一旦我的 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 的任何其他方式,然后选中对应于的复选框它。

谢谢

【问题讨论】:

  • 对于example
  • 抱歉,这个问题是关于 jquery Jtable 的。我已经更新了标签。感谢您的帮助。
  • 你能添加你的jtable的代码和你触发的函数吗?

标签: jquery html jquery-jtable


【解决方案1】:

试试这个:

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}

【讨论】:

    【解决方案2】:

    我是这样用的

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-30
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-30
      • 1970-01-01
      相关资源
      最近更新 更多