PDA

View Full Version : Using Filter()



irishdunn
13 Oct 2006, 12:37 PM
Hey there I wrote a baby function here to handle a selection element on my page and drill down the data in one of my grids. I cannot seem to get it to work though!


function drillDown(value){
application.userData.filter({0: /^value/i});
}

I keep debuggin and making sure value is correct, and sure enough it is. I have a buddy who said it looked like a "regex" statement, but i cant seem to find anything to help me out on this. jack save me!!!

jack.slocum
14 Oct 2006, 12:14 AM
You will need to create a RegExp obj in order to use a variable in the regex:



function drillDown(value){
var re = new RegExp("^"+value, "i");
application.userData.filter({0: re});
}

irishdunn
16 Oct 2006, 5:34 AM
Thanks jack I should have dug deeper in some javascript refernces, Is there an easy way to "de-filter" the grid, like a show all?

jack.slocum
16 Oct 2006, 8:35 AM
Filter actually removes the data. It's a true filter. You could probably capture a raw snapshot before filtering (dataModel.data) and restore it when you want to restore all.

irishdunn
16 Oct 2006, 12:32 PM
so if I captuer the userData.data to a var, when I want to "unfilter/showall" I then use the dataModel.load(captured var); method to show all of my original members?



function drillDown(value){
if(value == "") <-- showall!!!!
{
application.userData.load(application.USERDATA_DATAMODEL_SNAPSHOT);
}
else
{
application.USERDATA_DATAMODEL_SNAPSHOT = application.userData.data;
var re = new RegExp("^"+value, "i");
application.userData.filter({0: re});
}
}

jack.slocum
16 Oct 2006, 12:57 PM
What kind of model are you using?

jack.slocum
16 Oct 2006, 12:59 PM
Well, I guess with any data model, you can do this:



function drillDown(value){
if(value == "") <-- showall!!!!
{
application.userData.data = application.USERDATA_DATAMODEL_SNAPSHOT;
application.userData.fireTableDataChanged();
}
else
{
application.USERDATA_DATAMODEL_SNAPSHOT = application.userData.data.concat(); <-- make copy
var re = new RegExp("^"+value, "i");
application.userData.filter({0: re});
}
}


Notice I added the "concat()" call, that might not be needed.

irishdunn
17 Oct 2006, 12:58 PM
Well I cant get this code to work, I was missing the essential fireTableDataChanged() element but even with that addition I am still not loading the original Data in correctly. The problem probably lies in the fact that I am not taking a correct snapsho, so when I go to load in my snapshot it doesnt make a difference.

any ideas how to take a correct snapshot so I have the right element to use with the load() function jack?

jack.slocum
17 Oct 2006, 1:50 PM
Paste in all your code and I'll look at it.

irishdunn
17 Oct 2006, 3:30 PM
Im dicking with it right now, here ya go:



<script>
function drillDown(value){
if(value == "")
{
application.userData.load(application.USERDATA_DATAMODEL_SNAPSHOT);
application.userData.fireTableDataChanged();
}
else
{
application.USERDATA_DATAMODEL_SNAPSHOT = application.userData.data;
var re = new RegExp("^"+value, "i");
application.userData.filter({0: re});
}
}
</script>

irishdunn
19 Oct 2006, 5:20 AM
Im pretty sure that the only way this will roll is if I store the location of my XML page and just load(XMLSOURCE) back into my grid. Storing a temporary dataset is just proving to be a pain in the butt. I dont believe I am storing the correct material. I am storing the dataModel.data into my temp and then trying to call loadData(temp) but no go sir. As this app will be communicating with a server I will probably be fine just calling for a new XML page anyway.