简体   繁体   中英

jTable how getting selected row data

How can I get the data from the row I selected in 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,

$('#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:

/* 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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