简体   繁体   English

jTable如何获取选定的行数据

[英]jTable how getting selected row data

How can I get the data from the row I selected in jTable? 如何从jTable中选择的行中获取数据? Like for example I click on the first row and the data of the selected row goes to my inputbox. 例如,我单击第一行,所选行的数据进入我的输入框。

You can get the selected elements by registering for the event 'selectionChanged' as give below, 您可以通过注册事件“ 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);
            });
        }
    });

You can use below code to get all table records data in json string: 您可以使用以下代码获取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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM