1. #1
    Sencha User
    Join Date
    Jun 2011
    Posts
    6
    Vote Rating
    0
    shilong is on a distinguished road

      0  

    Default GridPanel: get selected record id vs. sorting

    GridPanel: get selected record id vs. sorting


    Hi forum

    I would like to detect the id of a selected record in a grid using the RowSelectionModel:

    Code:
    MyGrid = Ext.extend(Ext.grid.GridPanel, {
        sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
        [...]
        tbar: {
            id: 'gridTbar',
            items: [{
                text: 'Show record id',
                id: 'myButton',
                handler: function() {
                    var grid = this.ownerCt.ownerCt;
                    var selectionModel = grid.getSelectionModel();
                    var record = selectionModel.getSelected();
                    var recordId = grid.store.indexOf(record);
                    alert(recordId);
                }
            }]
        }
        initComponent:function() {
            // This renders the grid
            [...]
        }
        listeners:{
            'beforeexpand': function() {
                // This loads the grid (column definitions and data)
                [...]
            },
        }
    });
    The above code works fine, but I am facing the following problems:
    • store.indexOf() returns an index which depends on the (client side) sorting of the grid. This means the record has a different index everytime I click on one of the column headers.
    • The grid/store columns are built dynamically (read from the database). I do not know what columns the store contains and I can not rely on the store to contain any 'id' or 'key' column. I can not add such a column to the store because this might overwrite one of the existing columns in the store (which I do not know in advance).

    Is there a possibility to unambiguously identify the selected record through a cached id or key, which does not change when sorting/filtering the store?

    Thanks a lot.

    BTW, is there a better solution to access the grid whithin the button handler than
    Code:
    var grid = this.ownerCt.ownerCt;
    ?

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,639
    Vote Rating
    400
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    For accessing the grid, you can create a private function and then use:
    :: return this.getComponent('myGrid); where 'myGrid' is itemId for the grid.

    As for accessing a record, you will need to pass a unique id from the server as the grid uses this to distinguish the difference between records. I understand that your tables are random, but the client needs a way to reference.

    Regards,
    Scott.

  3. #3
    Sencha User
    Join Date
    Jun 2011
    Posts
    6
    Vote Rating
    0
    shilong is on a distinguished road

      0  

    Default


    Thanks Scott.

    Quote Originally Posted by scottmartin View Post
    For accessing the grid, you can create a private function and then use:
    :: return this.getComponent('myGrid); where 'myGrid' is itemId for the grid.
    True, that's definitely more elegant

    Quote Originally Posted by scottmartin View Post
    As for accessing a record, you will need to pass a unique id from the server as the grid uses this to distinguish the difference between records. I understand that your tables are random, but the client needs a way to reference.
    Hmm, so if I pass two identical records from the server, the grid has no way to distinguish them? I was hoping that the grid/store would assign a reference by itself which I could then access as well (like an index of an array or something).

    So I pass the reference from the server, but of course I don't want this (key-) column to be displayed in the grid. I can hide it using
    Code:
    myGrid.getColumnModel().setHidden(0, true);
    , but then the user would still be able to unhide the column using the header menu. Normally I would just remove the column from the columnModel, but in this case that would be rather pointless How can I prevent this column from being displayed?

    Thanks a lot!

  4. #4
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,639
    Vote Rating
    400
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    I usually like to create several column modules and then using grid.reconfigure to display different columns in the grid. You could build a dynamic list.

    As for the unique records, an id is created, but it will not have any relation to your records on the server.
    You can poke around the record object and see if there is anything you can use.

    Regards,
    Scott.

  5. #5
    Sencha User
    Join Date
    Jun 2011
    Posts
    6
    Vote Rating
    0
    shilong is on a distinguished road

      0  

    Default


    I solved the issue by adding a reference column to the store. The column is added to the columnModel to be easily acccessible through record.get(), but it can be kept hidden by setting the properties
    Code:
    hidden:true, hideable:false
    .

    Although this is not exactly what I was hoping for, I think I can live with that

    Thanks for your input.

Thread Participants: 1

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar