JSON store filtering based on stored data - solved
-
Hi all,
I am playing around with jsonStoreTable taken from here -> https://github.com/infiniteautomation/ma-dashboards/tree/3.3.x/UI/web/ngMango/components/jsonStoreTable
As I am still learning about subscription to data I have a problem on filtering data of my stores.
Filtering out stores which have certain string in their xid and then ordering them like I want is quite easy and understandable as it seems this data is accessible within my controller without problems.
this.orderedItems = this.$filter('filter')(this.items,{xid: "Report"}); this.orderedItems = this.$filter('orderBy')(this.orderedItems, this.tableOrder); this.count = this.orderedItems.length; this.latestXid = 'SavedReportData-' + this.orderedItems.length; this.nextXid = 'SavedReportData-' + (this.orderedItems.length + 1); this.dataTable = this.$filter('limitTo')(this.orderedItems,this.limit,(this.page-1)*this.limit);
The problem is that I would like to filter out some of my stores which have certain variable value in their jsonData object.
Lets say I have a following jsonStores:
{ "reportNo": 4, "approved": "testingstation", "name": "Thomas Einasto", "address": "Street name 34", "equipment": "Truck", "regno": "919BVY", "serialno": "2315824123", "firstentry": "2018-07-24", "tare": "2015", "carryingcapacity": "32153434", "finished":true }, { "reportNo": 7, "approved": "testingstation", "name": "Thomas Einasto", "address": "Street name 34", "equipment": "Truck", "regno": "919BVY", "serialno": "2315824123", "firstentry": "2018-07-24", "tare": "2015", "carryingcapacity": "32153434", "finished":false }
I would like to filter out all jsonStores which have reportNo 7. Filtering should work here just like filtering through xids from before work but I cannot access jsonStore because it is undefined in my filtering function.
Correct me if I am wrong but as I understand $q and $promise make a subscription to the backend and then the data gets passed asynchronously to the object after all promises have been resolved and that is why if I try to pass
console.log(this.dataTable[0]); console.log(this.dataTable[0].jsonData);
at the end of the filtering I see jsonData on the first object log but I get undefined on the second log as browser has got the data from the server as chrome says on the object that:
value below was evaluated just now
Can someone point me to the right directions on how should I handle this kind of filtering so that I would gain access to my jsonStores in the right time? I think this is about correctly timing my filtering based on an event when the data has been loaded but as I am still learning I am at a problem here.
Edit:
Got it filtered by changing html ng-repeat for the table.
<tr md-row ng-repeat='item in $ctrl.dataTable | filter:{ jsonData: {reportNo : 7}}' >
But still interested in how to do it through a controller.
Many Thanks
Thomas