Sorting FilteringSelect

3914
2
Jump to solution
04-16-2013 07:00 AM
SamirGambhir
Occasional Contributor III
Hello,
I have a data store with names of states queried from a feature layer as shown in this example. Here is my code:
//Populate the ComboBox with unique values  var stateName;  var values = [];  var testVals = {};   //Add option to display all district names to the ComboBox  values.push({   name : "All India"  });   //Loop through the QueryTask results and populate an array  //with the unique values  var features = results.features;  dojo.forEach(features, function(feature) {   stateName = feature.attributes.State_name;   if (!testVals[stateName]) {    testVals[stateName] = true;    values.push({     name : stateName    });   }  });  //Create a ItemFileReadStore and use it for the  //ComboBox's data source  var dataItems = {   identifier : 'name',   label : 'name',   items : values  };   var storeS = new dojo.data.ItemFileReadStore({   data : dataItems  });


This data store is attached to a filteringSelect:
dijit.byId("selStateM2").set("store", storeS);

Before ataching the store to my filteringSelect, I would like to sort the state names in alphabetical order. Here is my code:
var sortAttr = [{   attribute : "name",   ascending : true  }];  storeS.fetch({   query : {},   sort : sortAttr });

I need help in understanding how to push this sorted list to my filteringSelect.
Thanks
Samir
1 Solution

Accepted Solutions
SteveCole
Frequent Contributor
I specify the sorting over on the HTML side of things for filteringSelect by adding the following:

searchAttr="<your field name>" fetchProperties="{sort:[{attribute:'<your field name>', descending:false}]}"


The full HTML reference looks like this:

<input id="cboCrossStEnd" dojoType="dijit.form.FilteringSelect" checked="checked" searchAttr="CROSSST" name="WidgetName" pageSize="6" fetchProperties="{sort:[{attribute:'CROSSST', descending:false}]}" placeHolder="Select a road from the list" onChange="<your function here>" />


Here's my JS code for populating the filteringSelect (this is triggered via dojo.connect during the onLoad event):

function populateRdNameCbo(results) {  //Populate the dropdown list box with unique values  values = [];     testVals = {};    features = results.features;  dojo.forEach (features, function(feature) {   curName = feature.attributes.FULLNAME;   if (!testVals[curName]) {    testVals[curName] = true;    values.push({"OBJECTID":feature.attributes.OBJECTID,"RDNAME":feature.attributes.FULLNAME});   }  });    dataItems = {      identifier: "OBJECTID",      label: "RDNAME",      items: values  };    theStore = new dojo.data.ItemFileReadStore({data:dataItems});   dijit.byId("cboRdName").set("store", theStore);  }


My code also eliminates duplicate entries as it adds items to the list. Seems to work for me.

View solution in original post

0 Kudos
2 Replies
SteveCole
Frequent Contributor
I specify the sorting over on the HTML side of things for filteringSelect by adding the following:

searchAttr="<your field name>" fetchProperties="{sort:[{attribute:'<your field name>', descending:false}]}"


The full HTML reference looks like this:

<input id="cboCrossStEnd" dojoType="dijit.form.FilteringSelect" checked="checked" searchAttr="CROSSST" name="WidgetName" pageSize="6" fetchProperties="{sort:[{attribute:'CROSSST', descending:false}]}" placeHolder="Select a road from the list" onChange="<your function here>" />


Here's my JS code for populating the filteringSelect (this is triggered via dojo.connect during the onLoad event):

function populateRdNameCbo(results) {  //Populate the dropdown list box with unique values  values = [];     testVals = {};    features = results.features;  dojo.forEach (features, function(feature) {   curName = feature.attributes.FULLNAME;   if (!testVals[curName]) {    testVals[curName] = true;    values.push({"OBJECTID":feature.attributes.OBJECTID,"RDNAME":feature.attributes.FULLNAME});   }  });    dataItems = {      identifier: "OBJECTID",      label: "RDNAME",      items: values  };    theStore = new dojo.data.ItemFileReadStore({data:dataItems});   dijit.byId("cboRdName").set("store", theStore);  }


My code also eliminates duplicate entries as it adds items to the list. Seems to work for me.
0 Kudos
SamirGambhir
Occasional Contributor III
Thanks Steve,
It worked for me as well. The next thing I need to do is to sort the html list that is displayed after user selects state(s).
Samir
0 Kudos