views:

325

answers:

3

I have a list controller in my Dashcode project, it pulls its data from a dynamic source.

After my list controller has loaded its data I'd like to set it's selected index to 0 - so that information for the first item in the list is shown. I can't for the life of me figure out how to do this. I've tried:

function load()
{
    dashcode.setupParts();
    var list = document.getElementById("itemsList");
    //list.setSelectionIndexes(0); // nope
    //list.selectedIndex = 0; // nope
}
A: 
function load()
{
    dashcode.setupParts();
    var list = document.getElementById("itemsList");
    list.setSelectionIndexes([0]);
}
Jose Correa
Does not work for me too.
beefon
A: 

Does anyone have a solution for this problem? The answered code does not work for me.

I have a list binded to a datasource that gets requeried, which removes my selection from the list. I am trying to save the index of the selection on the list before it is refreshed so I can reselect it after the updating my datasource. I have looked in the List.js for the appropriate methods but they aren't working for me.

To grab the index (I am not allowing multiple selections) I have

        var indexB = document.getElementById("list2").object.selectionIndexes();
        var indexA = document.getElementById("list1").object.selectionIndexes();

Then I perform a query on a datasource that is binded to both lists.

        var dataSource = dashcode.getDataSource("model");
        dataSource.performQuery();

This causes me to lose the list selections so I am trying to reselect with

        document.getElementById("list1").object.setSelectionIndexes(indexA,false);
        document.getElementById("list2").object.setSelectionIndexes(indexB,false);

I believe the script executes past all the code but does not make the selections.

+1  A: 

No need to write any code for that. Edit the properties for the list in the inspector and uncheck allow empty selection in the attributes tab. With no null selection allowed the first item in the list will be selected when the list loads.

Vicente