简体   繁体   中英

How to make a row default selected in the jTable?

I got a jQuery jTable, in which I have a option to select a row form the table, but I want a row to be selected by default. How can I achieve this

 $('#selectType').jtable({
    selecting: true,
    actions: {
        listAction: //backend connection
    },
    fields: {
        type:{
          title:'Event Type',
          list: true,
        },
    },
    selectionChanged: function () {
        var $selectedRows = $('#selectType').jtable('selectedRows');
        if ($selectedRows.length > 0) {
            $selectedRows.each(function () {
                $type = $(this).data('record').type;
                console.log("type=" + $type);
                $('#Code').jtable(
                        'load',
                        {type: ($type)},
                        function () {
            //some function to load all the values selected
                        }
                );
            });
        }
    },
});
$('#selectType').jtable('load')

In the above code, I want the selectType to have a row selected by default. I have tried this

$('#selectType').jtable('load', {code:"Call"})

but its not working. Thanks.

I have added this function to select all the values in the table selected by default.

                            function () {
                            $selectedRows = $('#Code').jtable('selectedRows');
                            $('#Code').jtable('selectRows', $selectedRows);
                        }

It worked after making few more adjustments with my original code.

Thanks.

According to JTable documents it is possible by adding rowInserted event:

rowInserted: function (event, data) {
    if (data.record.type == 'specificType') {
         $('#StudentTableContainer').jtable('selectRows', data.row);
    }
}

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