Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap table: is it possible to call the function which sorts rows by column from code (without clicking the header)

http://jsfiddle.net/e3nk137y/4537/

<table data-toggle="table"
    >
    <thead>
        <tr>
            <th data-field="fruit" data-sortable="true">Item</th>
            <th data-field="date"  data-sortable="true">Date</th>
            <th data-field="type"  data-sortable="true">Type</th>
        </tr>
    </thead>
    <tbody>
        <tr><td>Pear  </td><td data-month="1">January</td> <td>Fruit</td></tr>
        <tr><td>Carrot</td><td data-month="3">March</td>   <td>Vegetable</td></tr>
        <tr><td>Apple </td><td data-month="2">February</td><td>Fruit</td></tr>
    </tbody>
</table>

In this fiddle is an example of a table. When you click the header, the table is sorted by the column belonging to that header.

My question is, if it's possible to trigger that function in some other way - from some other function. More generally: can I explicitly call the functions which are called as callbacks from various bootstrap widgets?

like image 223
UrbKr Avatar asked Sep 11 '25 12:09

UrbKr


1 Answers

You could programatically click the header. Does this achieve what you want?

$("th[data-field='fruit'] .sortable").click();

Fiddle

like image 167
Jaydo Avatar answered Sep 13 '25 03:09

Jaydo