-
3 Sep 2010 12:09 AM #1
store with distinct option
store with distinct option
Hallo!
I wrote a function, that you can use for distinct Element filtering.
The purpose is if you get resultsets with joins and have more entries, and you want to show the entries in more than one combobox you will get double entries, if you use the same store.
You may want to filter this "double entries".
Of corse you could make 2 requests to the server, but why bother the server with requests, if the client can do it(you may have performace issues on the server).
If your store looks like this:
Name
Anton
Toni
Toni
you will get this:
Name
Anton
Toni
Here the code:
function getDistinctStore(store,distinctKey){//info: store is a json store
var newstore=new Ext.data.ArrayStore();
var record;
store.data.each(function(rec){
if(record==null){
newstore.add(rec);
record=rec;
}
else
if(record.get(distinctKey)!=rec.get(distinctKey)){
newstore.add(rec);
record=rec;
}
});
return newstore;
}
It would be nice if Ext would have this as standard.
greets umit
-
5 Jul 2012 3:46 PM #2
Distinct rows from an Ext.data.XmlStore
Distinct rows from an Ext.data.XmlStore
Distinct rows from an Ext.data.XmlStore?? (Extjs 3.3.0 lib)
how can I retrieve distinct rows from an XmlStore,
Data Set
Job operation RunId Status
a launch 123 Pass
a lunch 123 Pass
a hold 124 Wait
a hold 124 wait
Result set,
I wanted to display only 2 rows based on RunId
a launch 123 Pass
a hold 124 wait
-
5 Jul 2012 11:37 PM #3
Hi,
use the filter function from the store,
i wrote this, when i was new to extjs and the implementation of mine has some kinda problems e.g. the store has to be sorted.
For your solution the filter function should do it, based on the criteria to filter(if you have the runid as seperate field in the store).
so something like:
You can also make a new store and add to to the store instead of filtering it.Code:var addedRunIds=[]; myXmlStore.filterBy(function(rec){if(addedRundIds.indexOf(rec.get("runid")==-1){//does not contain itaddedRunIds.add(rec.get("runid")); return true;} return false;}
greetsLast edited by umit; 9 Jul 2012 at 11:22 PM. Reason: -1 instead of 1
-
9 Jul 2012 1:46 PM #4
xmlstore filterby, extjs 3.3.0
xmlstore filterby, extjs 3.3.0
thanks umit,
i tried like this but getting errors..expected string, identifier, number!!
store.load({
callback : function() {
var addedRunIds=new Array();
for (var i = 0; i < store.getCount() - 1; i++) {
record = store.getAt(i);
store.filterBy({
function(record){
if(addedRunIds.indexOf(record.get("TESJobRunID")==1){//does not contain it
addedRunIds.add(record.get("TESJobRunID"));
return true;
}
return false;
}
});
}
}
});
-
9 Jul 2012 11:20 PM #5
Hi,
You have 2 variables with the name record, it is difficult to tell which one is the one you use, you should take a different name like record2, otherwise you have to work with this.record, but that's fuzzy.
And when you use indexOf it return -1 when it cant find the record, not 1, sry i wrote 1 ...
try this
What is the content of TESJobRunID ?Code:store.load({ callback : function() { var addedRunIds=[]; store.filterBy(function(rec){ if(addedRunIds.indexOf(record.get("TESJobRunID")==-1){//does not contain it //so add it and show it addedRunIds.push(rec.get("TESJobRunID")); return true; } return false; }); } });
Is it:
a launch 123 Pass
a lunch 123 Pass
a hold 124 Wait
a hold 124 wait
or
123
123
124
124
if it is the 1. you have to split it to get the id.
-
10 Jul 2012 8:14 AM #6
the contents of TESJobRunId are
123
123
124
124
-
10 Jul 2012 8:54 AM #7
do I need to declare the function variable record/rec, id of function(record, id)?
if not I can use this rec.get("TESJobRunID") in the function right ?
-
10 Jul 2012 10:50 AM #8
if I use your code inside the store.load then it is filtering only the first page of the grid and also i tried without store.load but it is not filtering.
----------------------------
var store = new Ext.data.XmlStore({
autoDestroy: true,
storeId: 'myStore',
proxy: proxy,
root : "standard",
record: 'standardData',
idPath: 'rowId',
totalProperty: '@totalCount',
autoLoad: false,
paramNames: {
start: 'startRow',
limit: 'recordSize'
},
fields: fieldObjectList
});
store.load({
callback : function() {
var addedRunIds=[];
store.filterBy(function(rec){
if(addedRunIds.indexOf(rec.get("TESJobRunID"))==-1){//does not contain it
//so add it and show it
addedRunIds.push(rec.get("TESJobRunID"));
return true;
}
return false;
});
}
});
/* create the grid */
var grid = new Ext.grid.GridPanel({
store : store,
columns : displayList,
renderTo : '#divName#',
width : "100%",
autoHeight : true,
plugins: [filterRow],
stripeRows: true,
layout : 'fit',
viewConfig : {
forceFit : true
},
bbar : [new Ext.PagingToolbar({
store : store,
displayInfo : true,
pageSize : 10,
params:{
startRow: 0,
recordSize: 10
}
})]
});
-----------------------------
-
10 Jul 2012 11:17 AM #9
Hi,
you can use it by record.get("xyz") you don't need more variables.
What do you mean by: it's filtering the first page? does it have many pages? do you load only a part of the whole runids by the server?
You have to load and filter afterwards. So everytime you load, you have to filter. You can use an event, so that it autofilters when you load. The syntax would be:
But be careful with the filter, whenever you iterate it, you will only get the elements, that are shown. So when you use the store for something else too, use another store with the same structure.Code:store.on("load",function(){ //your filter function });
-
10 Jul 2012 11:51 AM #10
thanks umit, it works!!!
yes i have around 1000 records and i am using pagination too, the issue i m facing now is records numbers shows in the pagination, it is showing the actual records# from store not the filtered one.
Similar Threads
-
count distinct for a particular column
By emmas in forum Ext GWT: DiscussionReplies: 1Last Post: 23 Aug 2010, 1:26 PM -
Editable Grid with All ComboBoxes, and Distinct values?
By jwong in forum Ext 2.x: Help & DiscussionReplies: 5Last Post: 9 Dec 2009, 3:52 AM -
How to specify jsonData as option in store.load()?
By dbassett74 in forum Ext 3.x: Help & DiscussionReplies: 9Last Post: 16 Jul 2009, 5:34 PM -
Editable Grid with All ComboBoxes, and Distinct values?
By jwong in forum Ext GWT: Help & Discussion (1.x)Replies: 4Last Post: 19 Jun 2008, 2:16 PM -
how to distinct editorGrid's cellclick from celldblclick
By lixiaoxu85 in forum Ext 2.x: Help & DiscussionReplies: 0Last Post: 28 Apr 2008, 7:13 PM


Reply With Quote