javascriptangularjssmart-table

angularjs smart-table programmatically sort


I have a table set up using the smart-table plug in for AngularJS. Everything appears to work nicely. Rather than having the user click on the table header to trigger a sort, I'd like to programmatically trigger sorting from my Angular controller. I do not see a way of doing this in the documentation here:

http://lorenzofox3.github.io/smart-table-website/

Am I overlooking something?


Solution

  • Found this on JSFiddle, might help you: http://jsfiddle.net/vojtajina/js64b/14/

    <script type="text/javascript" ng:autobind
    src="http://code.angularjs.org/0.10.5/angular-0.10.5.js"></script>
    
    <table ng:controller="SortableTableCtrl">
        <thead>
            <tr>
                <th ng:repeat="(i,th) in head" ng:class="selectedCls(i)" ng:click="changeSorting(i)">{{th}}</th>
            </tr>
        </thead>
        <tbody>
            <tr ng:repeat="row in body.$orderBy(sort.column, sort.descending)">
                <td>{{row.a}}</td>
                <td>{{row.b}}</td>
                <td>{{row.c}}</td> 
            </tr>
        </tbody>
    </table>