jTable如何获取选定的行数据

时间:2014-06-22 01:57:21

标签: javascript php jquery-jtable

如何从jTable中选择的行中获取数据?例如,我单击第一行,所选行的数据将转到我的输入框。

2 个答案:

答案 0 :(得分:2)

您可以通过注册活动来获取所选元素" selectionChanged'如下,

$('#tableName').jtable({
        selecting: true,
        columnResizable: false,
        actions: {
        },
        fields: {
            KeyId: {
                key: true,
                create: false,
                list: false
            },
            Name: {
                title: 'Name',
                sorting: true
            },
            Description: {
                title: 'Description',
                create: false,
                list: false
            },
            StartDate: {
                title: 'Start Date'
            },
            EndDate: {
                title: 'End Date'
            },
            Status: {
                title: 'Status',
                list: false
            }
        },
        //Register to selectionChanged event to handle events
        selectionChanged: function () {
            var $selectedRows = $('#tableName').jtable('selectedRows');
            $selectedRows.each(function () {

                var record = $(this).data('record');
                var keyid = record.KeyId;
                var name = record.Name;

                alert(" KeyId:" + keyid + " Name:" + name);
            });
        }
    });

答案 1 :(得分:0)

您可以使用以下代码获取json字符串中的所有表记录数据:

/* Read each record and add it to json */
var $selectedRows = $('#your_table').jtable('selectedRows'),records = [];
$selectedRows.each(function () {
    var record = $(this).data('record');
    records.push(record);
});
var josn_data = JSON.stringify(records);