I am building options for a drop down menu on a toolbar from a database table, giving the id's for the options the same value as the index in the table, however ordered alphabetically by the description of the option. The visual drop down comes out sorted nicely, however when I ask for a list of all options, they are sorted by id, i.e. getAllListOptions() and forEachListOption(). Are there ways to lookup the option list in the "right" order to pick say the first option in the list, other than sorting the list again myself?
To emphasize, the problem is ID's are not in ascending order when options are sorted by description, however dhtmlx order them internally in ascending order by value instead of by name as they should. I.E, say option with ID of 8 comes out top of list, the first option in the internal list should be "8" not what ever is the smallest ID (in my case 2).
Website is MVC and back-end is MS SQL Server, data structures, like option lists, are passed back through razor scripts as XML.
I.E. the ajax call to get the option list is passed through the bussiness layer to the DAL, which request a list of objects sorted on description. The razor script then creates the XML like this
<item id="tbbOptions" type="buttonSelect" title="@(Messages.Lookup("Config"))" selected="-1" text="@Messages.Lookup("Config_Select")">
@foreach (Analysis oAnalysis in Model.Analysis)
{
if (!string.IsNullOrEmpty(oAnalysis.SecondaryField))
{
<item type="button" id="@(oAnalysis.ID)" img="blueprint.png" imgdis="blueprint.png" text="@string.Format("{0}", oAnalysis.Description)" />
}
else
{
<item type="button" id="@(oAnalysis.ID)" img="blueprint.png" imgdis="blueprint.png" text="@string.Format("{0}", oAnalysis.Description)" />
}
}
</item>
SQL query:
public List<Analysis> GetConfig()
{
return UnitOfWork.Database.Fetch<Analysis>("SELECT * FROM [Analysis] ORDER BY [Description]");
}
After scouring through the javascript source code for the dhtmlx toolbar, I constructed a solution that seem to do what I want. Apparently there are no functions that expose the visual options, so only way to access is through attributes on the object.
In case others run into the same issue, here is what I did: