Datastore filtering on select on form

Hi guys,

I have a dataview container which i want to filter using values from a search form. The dataview is populated using a datastore and I’d like to filter it based on the form.

the select in the form is :

var crewSearchFormData = [
{type: “select”, name: “searchlocation”, label: “Location”} ];
crewSearchForm = searchLayout.cells(“a”).attachForm(crewSearchFormData);

I need to populate this from a datastore :
var locationListDS = new dhtmlXDataStore({
url:“ccproc/adminmgmt.php?action=getLocationsDS”,
datatype:“xml”}
);

I thought this would work, but it doesn’t seem to ?
var locationSelect = crewSearchForm.getSelect(“searchlocation”);
locationSelect.sync(locationListDS);

so my first question is… how to populate the select options from the datastore?

Secondly, I have the dataview populated from the datastore…

var crewListDS = new dhtmlXDataStore({
url:“ccproc/crewmgmt.php?action=getCrewDS”,
datatype:“xml”}
);
var crewResultsDV;

crewResultsDV = new dhtmlXDataView({
container: “searchpanel”,
type: {template: “

#crewname#
#locname#
#mobile#
#email#
”,
height: 15},
drag: false});

crewResultsDV.sync(crewListDS);
…how do I filter this dataview filtering the datastore using the select in the search form.

thanks!

getSelect return native html select object, not a dhtmlx object, so it can’t be loaded from datastore.

…how do I filter this dataview filtering the datastore using the select in the search form.

You can call

   locationListDS.filter("#location#",  crewSearchForm.getFormData().searchlocation);

Hi Stanislav,

thanks for the response. So, ok I’ve changed the code as per your thoughts:

This is the code now which searches the location:
crewListDS.filter(function(obj,value){
if (obj.location==value) return true;
return false;
},crewSearchForm.getFormData().searchlocation);

this allows me to filter the datastore based on the select input of the locations. And when I click on an entry in the dataview it loads the form thats bound to it too. However, the value displaying in the dataview for location is the index and not the text. I think this is required to load the form and to filter the results. But is there anyway that i can translate the index in in the dataview to the option text? (for example like the optionsConnector)…

just to explain again - ‘location’ is sent from the server as the index value for the select inputs, but i need to translate that to a text value in the dataview (allowing for any changes to the location in the form to update the dataview and persist back to the database…)

thanks

You can use templates of dataview to show any value, if you have text in the data objects you can just define

template:"#text#"

or if you have some separate objects with index->text relation you can use

template:function(obj){ return texts[obj.location]; }

where “texts” is a such object

Hi Stanslav,

it would seem that the second option is what I need -
template:function(obj){ return texts[obj.location]; }

here is my template:
crewResultsDV = new dhtmlXDataView({
container: “searchpanel”,
type: {
template: “

#crewname#
#location#
#mobile#
#email#
”,
height: 15
},
});

which is populated by :

$getCrewSQL = “SELECT crewid, crewname, mobile, email, addrline1, addrline2, addrline3, addrline4, emergencycontact, notes, location FROM crew ORDER BY crewname ASC”; $conn->render_sql($getCrewSQL,“crewid”,“crewname,location,mobile,email,addrline1,addrline2,addrline3,addrline4,emergencycontact,notes”);

(location is a foreign key to a lookup table location with fields locationid,locationtext)

the value #location# is an int value, e.g. 1=EU, 2=UK, 3=US etc. and these are used in the selects, I’m just not sure how I put the objects with index->text into the datastore?

thanks for your help!

DataStore or DataView can’t store separate collections, which are not part of main dataset.
The best possible solution would be to store both id and text values in the properties of dataview ( one for db operation, second for visual rendering ) and after changing value through select - change location text as well.