Santha Kumar
Santha Kumar

Reputation: 83

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.

Upvotes: 1

Views: 239

Answers (2)

ali-myousefi
ali-myousefi

Reputation: 872

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);
    }
}

Upvotes: 0

Santha Kumar
Santha Kumar

Reputation: 83

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.

Upvotes: 0

Related Questions