Filter Options:


View Image!
var viewModelNewArrivals=function(){ var self=this; self.activeFilter = ko.observable(); self.newArrivalsVehicleData = ko.observableArray(newarrivalsdata.newarrivals); self.categories=newarrivalsdata.categories; self.parttypesd=newarrivalsdata.parttypes; self.headers = [ {title:'Arrival Date',sortPropertyName:'arrivaldate', asc: true, active: false}, {title:'Stock',sortPropertyName:'stocknumber', asc: true, active: false}, {title:'Year',sortPropertyName:'year', asc: true, active: false}, {title:'Make',sortPropertyName:'make', asc: true, active: false}, {title:'Model',sortPropertyName:'model', asc: true, active: false}, {title:'VIN',sortPropertyName:'vin', asc: true, active: false}, {title:'Miles',sortPropertyName:'miles', asc: true, active: false}, {title:'Images',sortPropertyName:'hasimages', asc: true, active: false} ]; self.activeSort = ko.observable(function(){return 0;}); //set the default sort self.sort = function(header, event){ //if this header was just clicked a second time if(header.active) { header.asc = !header.asc; //toggle the direction of the sort } //make sure all other headers are set to inactive ko.utils.arrayForEach(self.headers, function(item){ item.active = false; } ); //the header that was just clicked is now active header.active = true;//our now-active header var prop = header.sortPropertyName; var ascSort = function(a,b){ return a[prop] < b[prop] ? -1 : a[prop] > b[prop] ? 1 : a[prop] == b[prop] ? 0 : 0; }; var descSort = function(a,b){ return a[prop] > b[prop] ? -1 : a[prop] < b[prop] ? 1 : a[prop] == b[prop] ? 0 : 0; }; var sortFunc = header.asc ? ascSort : descSort; //store the new active sort function self.activeSort(sortFunc); }; self.selectedYear= ko.observable(); self.selectedMake = ko.observable(); self.selectedModel = ko.observable(); self.selectedPart = ko.observable(); self.resetFilters=function(){ self.selectedYear(null); self.selectedMake(null); self.selectedModel(null); self.selectedPart(null); } self.filteredTableData = ko.computed(function(){ var result;         if(self.selectedYear() || self.selectedMake() || self.selectedModel()|| self.selectedPart()){             result = ko.utils.arrayFilter(self.newArrivalsVehicleData(), function(item) { return ( (self.selectedYear()?item.year == self.selectedYear():true) && (self.selectedMake()?item.make == self.selectedMake():true) && (self.selectedModel()?item.model == self.selectedModel():true) && (self.selectedPart()?(item.parttypes.indexOf(self.selectedPart().toString())>-1):true)); });         } else {             result = self.newArrivalsVehicleData();         } return result.sort(self.activeSort());     }); self.makes = ko.computed(function() { var makes = ko.utils.arrayMap(self.filteredTableData(), function(item){ return item.make}); var sorted=ko.utils.arrayGetDistinctValues(makes).sort(); return sorted; }); self.models = ko.computed(function() { var models = ko.utils.arrayMap(self.filteredTableData(), function(item){ return item.model}); var sorted=ko.utils.arrayGetDistinctValues(models).sort(); return sorted; }); self.years = ko.computed(function() { var years = ko.utils.arrayMap(self.filteredTableData(), function(item){ return item.year}); var sorted=ko.utils.arrayGetDistinctValues(years).sort(); return sorted.reverse(); }); self.parttypes = ko.computed(function() { var partypesArr = ko.utils.arrayMap(self.filteredTableData(), function(item){ return item.parttypes}); var parttypes=[]; ko.utils.arrayForEach(partypesArr, function(item) { parttypes.push.apply(parttypes, item) }); var distpartypes=ko.utils.arrayGetDistinctValues(parttypes); var validatedParttypes=ko.utils.arrayFilter(newarrivalsdata.parttypes, function(item){ return (distpartypes.indexOf(item.id.toString())>-1) ; }); var validatedParttypesEx= ko.utils.arrayMap(validatedParttypes,function(item){ var categoryname= ko.utils.arrayFirst(newarrivalsdata.categories,function(cat){ return cat.id==item.category_id; })||""; return {value:item.id,text:categoryname.label.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();})+" - "+item.parttype} }); return validatedParttypesEx; }); self.validVehiclePartTypes =ko.observableArray(); self.showPartTypes=function(data){ self.validVehiclePartTypes(data.parttypes); // $('#myModal').modal('show'); } self.vehiclePartTypes = ko.computed(function() { var validatedParttypes=ko.utils.arrayFilter(newarrivalsdata.parttypes, function(item){ return (self.validVehiclePartTypes().indexOf(item.id.toString())>-1) ; }); var validatedParttypesEx= ko.utils.arrayMap(newarrivalsdata.categories,function(cat){ var parttypes=ko.utils.arrayFilter(validatedParttypes, function(item){ return (item.category_id==cat.id) ; }); return {category:cat,parttypes:parttypes}; }) return validatedParttypesEx; }); } ko.applyBindings(new viewModelNewArrivals(),document.getElementById("newArrivals")); }); function openpopup(url) { testwindow = window.open (url, "mywindow", "location=0,status=0,scrollbars=1,width=700,height=700"); } function openarrival(url) { testwindow = window.open (url,'_self'); }