Pergunta

I have site with a listgrid and a openlayers map with points. When i cklick on one of these, the application shall scroll and mark this record. This works with a standard listgrid, but with a grouped listgrid it does not work.

lg = new ListGrid();
lg.setWidth(330);
lg.setDataSource(ds1);
lg.setAutoFetchData(true);
lg.setSortField("KU_NAME");
lg.setGroupStartOpen(GroupStartOpen.ALL);
lg.setGroupByField("KU_NAME");
lg.setShowFilterEditor(true);

kuName = new ListGridField("KU_NAME", "Künstler Name",150);

// Standorte
ListGridField stdOrt = new ListGridField("STDORT_NR","Standort Nr.");
ListGridField oid = new ListGridField("OID","OID.");
lg.setFields(stdOrt,kuName,oid);

and the select:

String stdortOID = stdOrtOIDjso.toString();
ListGridRecord[] records = lg.getRecords();
    int i;
    for (i = 0; i < records.length; i++) {
        if (records[i].getAttribute("OID").equalsIgnoreCase(stdortOID)){
            break;
    }
}
lg.deselectAllRecords();
lg.selectRecord(i);
lg.scrollToRow(lg.getRecordIndex(record));

the reason is that in the record is only the value of the group name and the other attributs are unavailable.

Foi útil?

Solução

When grouping is enabled, all data are "transformed" into tree and listgrid itself contains data for groups so you have to look for your record in this tree. Replace last 3 lines with (modified) Vittorio Paternostro suggestion:

Tree tree = lg.getGroupTree();
if (tree != null) {
    TreeNode node = tree.find("OID", stdortOID);
    if (node != null) {
        lg.selectSingleRecord(node);
        lg.scrollToRow(getRecordIndex(node));
        lg.markForRedraw();
    }
}

Note: Instead of deselectAllRecords + selectRecord use simplified selectSingleRecord.

Outras dicas

I had the same need and the following works fine for me. You can use getGroupTree() and search the desired property in it (column value) without worrying about grouping. Make sure you search for unique values (i.e. a unique key) to identify a precise node.

    Tree tree = getGroupTree();
    if (tree != null) {
        TreeNode node = tree.find("property", "value");
        if (node != null) {
            selectSingleRecord(node);
            scrollToRow(getRecordIndex(node));
            markForRedraw();
        }
    }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top