簡體   English   中英

jTable如何獲取選定的行數據

[英]jTable how getting selected row data

如何從jTable中選擇的行中獲取數據? 例如,我單擊第一行,所選行的數據進入我的輸入框。

您可以通過注冊事件“ 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);
            });
        }
    });

您可以使用以下代碼獲取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