user1702486
user1702486

Reputation: 107

how to auto select a grid record in extjs by using id?

I want to load a grid by highlighting a specific row by sending id attribute in extjs. I cannot choose the record for now. How can i do it? thanks....

I tried some codes which are commented in the code are. you can see below.

var GrideAktar = function (bilgim) {
    arr = bilgim.split(",");
    bilgi = arr[0];
    secilecek_id = arr[1];

    harita.hide();
    izgaralar.hide();
    chartlar.hide();
    izgara_yp_is_emirleri.hide();


    izgaralar.show();
    izgaralar.setHeight(merkez.getHeight());
    fileStore_yon.loadById(bilgi);
    tree.treeRefresh();

    cuIzgaraKay = null;
    cuAgacNode = bilgi;
    cuAgacSeciliNode = NodeParser(bilgi);
    cuAgacSeciliSehir = SehirParser(bilgi)
    fileGrid_yon.setHeight(merkez.getHeight());
    //fileGrid_yon.getSelectionModel().selectFirstRow();
    //fileGrid_yon.getSelectionModel().valueOf(id);
    //fileGrid_yon.getSelectionModel().selectRow(1);

    //   var idx = fileGrid_yon.getStore().indexOfId(secilek_id);
    //var rowEl = fileGrid_yon.getView().getRow(idx);
    //rowEl.scrollIntoView(fileGrid_yon.getGridEl(),false);
    Ext.select(secilecek_id);
    raporAlanListesiWindow.hide();
    //fileGrid_yon.getSelectionModel().selectRow( this.getStore().indexOfId(id) ); //raporSecenekleriForm.hide(); 
}

Upvotes: 3

Views: 9532

Answers (3)

CD..
CD..

Reputation: 74116

Use:

grid.getSelectionModel().select(store.getById(id));

Which will select the record in store by id in grid.

Upvotes: 8

Badari
Badari

Reputation: 21

var index = gridPanel.store.find('fieldName', fieldValue);
gridPanel.getSelectionModel().select(gridPanel.store.getAt(index));

Upvotes: 1

Reimius
Reimius

Reputation: 5712

This looks like a race condition issue. I'm guessing that your code creates a grid that loads from a remote source using ajax or something. Try imbedding the row selection code in the 'load' event of the store:

var GrideAktar = function (bilgim) {
    arr = bilgim.split(",");
    bilgi = arr[0];
    secilecek_id = arr[1];

    harita.hide();
    izgaralar.hide();
    chartlar.hide();
    izgara_yp_is_emirleri.hide();


    izgaralar.show();
    izgaralar.setHeight(merkez.getHeight());
    fileStore_yon.on("load", function(){
        fileGrid_yon.getSelectionModel().select(fileStore_yon.getById(id));
    });
    fileStore_yon.loadById(bilgi);
    tree.treeRefresh();

    cuIzgaraKay = null;
    cuAgacNode = bilgi;
    cuAgacSeciliNode = NodeParser(bilgi);
    cuAgacSeciliSehir = SehirParser(bilgi)
    fileGrid_yon.setHeight(merkez.getHeight());
    //fileGrid_yon.getSelectionModel().selectFirstRow();
    //fileGrid_yon.getSelectionModel().valueOf(id);
    //fileGrid_yon.getSelectionModel().selectRow(1);

    //   var idx = fileGrid_yon.getStore().indexOfId(secilek_id);
    //var rowEl = fileGrid_yon.getView().getRow(idx);
    //rowEl.scrollIntoView(fileGrid_yon.getGridEl(),false);
    Ext.select(secilecek_id);
    raporAlanListesiWindow.hide();
    //fileGrid_yon.getSelectionModel().selectRow( this.getStore().indexOfId(id) ); //raporSecenekleriForm.hide(); 
}

Upvotes: 1

Related Questions