So i am trying to sort multiple columns at the same time. Ex. if i am sorting a table in ascending order to see if my accounts are activated or not. then at the same time i want the list to be automatically sorted in ascending order by there last name. Here is the code:
<table class="table table-hover admin-table">
<thead>
<tr>
<th data-bind="click: function () { setSort('FirstName'); }, css: { 'active-sort': $root.sortColumn() == 'FirstName', 'asc': $root.sortColumn() == 'FirstName' && $root.sortDirection() == 'ASC', 'desc': $root.sortColumn() == 'FirstName' && $root.sortDirection() == 'DESC' }">First Name<i></i></th>
<th data-bind="click: function () { setSort('LastName'); }, css: { 'active-sort': $root.sortColumn() == 'LastName', 'asc': $root.sortColumn() == 'LastName' && $root.sortDirection() == 'ASC', 'desc': $root.sortColumn() == 'LastName' && $root.sortDirection() == 'DESC' }">Last Name<i></i></th>
<th data-bind="click: function () { setSort('Email'); }, css: { 'active-sort': $root.sortColumn() == 'Email', 'asc': $root.sortColumn() == 'Email' && $root.sortDirection() == 'ASC', 'desc': $root.sortColumn() == 'Email' && $root.sortDirection() == 'DESC' }">Email<i></i></th>
<th data-bind="click: function () { setSort('IsActivated', 'LastName'); }, css: { 'active-sort': $root.sortColumn() == 'IsActivated', 'asc': $root.sortColumn() == 'IsActivated' && $root.sortDirection() == 'ASC', 'desc': $root.sortColumn() == 'IsActivated' && $root.sortDirection() == 'DESC' }">Is Activated<i></i></th>
<th data-bind="click: function () { setSort('IsAdministrator'); }, css: { 'active-sort': $root.sortColumn() == 'IsAdministrator', 'asc': $root.sortColumn() == 'IsAdministrator' && $root.sortDirection() == 'ASC', 'desc': $root.sortColumn() == 'IsAdministrator' && $root.sortDirection() == 'DESC' }">Is Administrator<i></i></th>
<th></th>
</tr>
</thead>
<tbody data-bind="foreach: accounts">
<tr>
<td data-bind="text: FirstName"></td>
<td data-bind="text: LastName"></td>
<td data-bind="text: Email"></td>
<td data-bind="text: IsActivated() ? 'Yes' : 'No'"></td>
<td data-bind="text: IsAdministrator() == 'true' ? 'Yes' : 'No'"></td>
<td>
<button class="btn-std" data-bind="click: $root.showUpdateModal">Update</button>
<div class="clearfix"></div>
<button class="btn-std" data-bind="click: $root.resendVerificationEmail, visible: !IsActivated()">Resend Verification Email</button>
</td>
</tr>
</tbody>
</table>
Java Script:
self.renderUsers = function (pageIndex, pageSize) {
var filteredUsers;
if (self.sortColumn() == "IsActivated") {
if (self.sortDirection() == "ASC") {
filteredUsers = Enumerable.from(allAccounts).orderBy("$." + self.sortColumn() + "()").skip((pageIndex - 1) * pageSize).take(pageSize).toArray();
} else {
filteredUsers = Enumerable.from(allAccounts).orderByDescending("$." + self.sortColumn() + "()").skip((pageIndex - 1) * pageSize).take(pageSize).toArray();
}
}
else {
if (self.sortDirection() == "ASC") {
filteredUsers = Enumerable.from(allAccounts).orderBy("$." + self.sortColumn() + "().toUpperCase()").skip((pageIndex - 1) * pageSize).take(pageSize).toArray();
} else {
filteredUsers = Enumerable.from(allAccounts).orderByDescending("$." + self.sortColumn() + "().toUpperCase()").skip((pageIndex - 1) * pageSize).take(pageSize).toArray();
}
}
self.accounts(filteredUsers);
};