<script type="text/javascript">
var viewModel;
function sourceData() {
return [
{ "Product_ID": 1, "Product_Name": "Chai",
"Category_ID": 1, "Quantity_Per_Unit": "10 boxes x 20 bags", "Unit_Price": 18.0 },
{ "Product_ID": 2, "Product_Name": "Chang",
"Category_ID": 1, "Quantity_Per_Unit": "24 - 12 oz bottles" },
{ "Product_ID": 3, "Product_Name": "Aniseed Syrup",
"Category_ID": 2, "Quantity_Per_Unit": "12 - 550 ml bottles", "Unit_Price": 10.0 },
{ "Product_ID": 4, "Product_Name": "Chef Anton's Cajun Seasoning",
"Category_ID": 2, "Quantity_Per_Unit": "48 - 6 oz jars", "Unit_Price": 22.0 },
{ "Product_ID": 5, "Product_Name": "Chef Anton's Gumbo Mix",
"Category_ID": 2, "Quantity_Per_Unit": "36 boxes", "Unit_Price": 21.35 },
{ "Product_ID": 6, "Product_Name": "Grandma's Boysenberry Spread",
"Category_ID": 2, "Quantity_Per_Unit": "12 - 8 oz jars", "Unit_Price": 25.0 }
];
}
function ViewModel(sessionId) {
var productView = new wijmo.data.ArrayDataView(sourceData());
this.products = productView;
this.clearFilter = function () {productView.filter(null);};
this.filterBeverages = function () {productView.filter({ Category_ID: 1 });};
this.filterCondiments = function () {productView.filter({ Category_ID: 2 });};
this.sortId = function () {productView.sort("Product_ID");};
this.sortPrice = function () {productView.sort("Unit_Price desc");};
this.clearPaging = function () {productView.pageSize(0);};
this.setPaging = function () {productView.pageSize(4);};
this.prevPage = function () {productView.prevPage();};
this.nextPage = function () {productView.nextPage();};
this.add = function () {productView.add({
Product_ID: 100,
Product_Name: "Tomato",
Category_ID: 1,
Unit_Price: 5
});
productView.commitEdit();
};
this.deleteCurrent = function () {productView.remove();};
this.doublePrice = function () {
productView.editItem();
productView.currentEditItem().Unit_Price *= 2;
productView.commitEdit();
};
}
$(document).ready(function () {
viewModel = new ViewModel();
ko.applyBindings(viewModel);
});
</script>
|