I have a list of records returned from the server for the last 24 months. There is a select menu where the user can select "Last 18 months", "Last 12 months" or "Last 24 months".
The default is 24 months, so when the user comes to the page for the first time, the full list is retrieved from the server. Now, without using a postback (thus saving a trip to the server), can I filter the data depending upon what the user selects from the select menu?
I am using ASP.NET MVC4 with jQuery mobile and knockout.js.
Table in the view (html):
<table style="width:100%;">
<tbody data-bind="foreach: TankMixRows">
<tr>
<td data-bind="text: ProductName"></td>
<td data-bind="text: AI"></td>
<td></td>
<td data-bind="text: MOAHerbicide"></td>
<td data-bind="text: MOAInsecticide"></td>
<td data-bind="text: MOAFungicide"></td>
</tr>
</tbody>
</table>
Javascript:
function MOAViewModel() {
var self = this;
self.TankMixRows = ko.observableArray([]);
self.getTankMixRows = function () {
$.ajax({
type: "GET",
url: '@Url.Action("jsonModeOfAction", "WorkOrders")',
data: {
ID: '@Model.RecFieldId'
},
success: function (data) {
self.TankMixRows(data);
}
});
}
//Load initial state from server and populate viewmodel
self.getTankMixRows();
}
ko.applyBindings(new MOAViewModel());