Results 1 to 2 of 2

Thread: Updating cell value in grid (cellclick problem)

  1. #1
    Sencha User
    Join Date
    Apr 2010
    Posts
    3
    Vote Rating
    0
      0  

    Default Updating cell value in grid (cellclick problem)

    Hi, im having a problem setting a value in a grid (in the cellclick event). I searched in the grid faq and on many forums but not found nothing about this problem.

    Well, here is my code:

    Code:
    var myData = [
                ['Func 1', '2', '3', '1', '5', 0],
                ['Func 2', '2', '3', '2', '5', 0],
                ['Func 3', '2', '3', '3', '5', 0],
                ['Func 4', '2', '3', '4', '5', 0],
                ['Func 5', '2', '3', '5', '5', 0],
                ['Func 6', '2', '3', '6', '5', 0]
            ];
            
            var store = new Ext.data.ArrayStore({
                fields: [
                   {name: 'cajero'},
                   {name: 'hora2'},
                   {name: 'hora3'},
                   {name: 'hora4'},
                   {name: 'hora5'},
                   {name: 'horas', type: 'int'}
                ]
            });
            
            function myRenderer(val) {
                return '<span style="font-weight:bold;">' + val + '</span>';
            }
    
    
            store.loadData(myData);
            
            var grid = new Ext.grid.GridPanel({
                store: store,
                sm: new Ext.grid.CellSelectionModel({singleSelect:true}),
                cm: new Ext.grid.ColumnModel([
                    new Ext.grid.RowNumberer(),
                    {
                        id       : 'cajero',
                        header   : 'Cajera', 
                        width    : 50, 
                        sortable : false, 
                        dataIndex: 'cajero',
                        renderer: myRenderer
                    },
                    {
                        id       : 'hora2',
                        header   : '06:30', 
                        width    : 50, 
                        sortable : false, 
                        dataIndex: 'hora2'
                    },
                    {
                        id       : 'hora3',
                        header   : '07:00', 
                        width    : 50, 
                        sortable : false, 
                        dataIndex: 'hora3'
                    },
                    {
                        id       : 'hora4',
                        header   : '07:30', 
                        width    : 50, 
                        sortable : false, 
                        dataIndex: 'hora4'
                    },
                    {
                        id       : 'hora5',
                        header   : '08:00', 
                        width    : 50, 
                        sortable : false, 
                        dataIndex: 'hora5'
                    },
                    {
                        id       : 'horas',
                        header   : 'Horas', 
                        width    : 50, 
                        sortable : false, 
                        dataIndex: 'horas'
                    }
                ]),
                stripeRows: false,
                autoExpandColumn: 'cajero',
                height: 350,
                width: 600,
                title: 'Recursos',
                // config options for stateful behavior
                stateful: false,
                id: 'grid',
                stateId: 'grid',
                listeners: {
                    //Manejo el click de una celda
                    cellclick: function(grid, rowIndex, columnIndex, e) {
                        cont = 0;
                        var record     = grid.getStore().getAt(rowIndex);
                        var selCell    = grid.getSelectionModel().getSelectedCell();
                        var fieldName  = grid.getColumnModel().getDataIndex(selCell[1]);
                        var cantCols   = grid.getColumnModel().getColumnCount();
                        var cellValue  = parseInt(record.get(fieldName));
                        var cellActual = Ext.get(grid.getView().getCell(rowIndex, columnIndex));
                        
                        if (columnIndex == 1 || columnIndex == 6) {
                            return false;
                        }
                        
                        cellActual.toggleClass('error');
                        cont = 0;
                        
                        for (var i = 1; i < cantCols; i++) {
                            if (Ext.get(grid.getView().getCell(rowIndex, i)).hasClass('error')) {
                                cont++;
                            }
                        }
                                            //record.set('horas', cont);
                        record.data['horas'] = cont;
                                            record.commit();
    
                    }
                }
            });
            grid.render('grilla');
    What i want is when i click one cell it change its css class and update "horas" value in the row that the cell is contained. The problem comes when the record.commit() method is called (or when i use record.set() method). I need to click twice in the cells to change its class and when i click in another cell the previous one "loses" the css class that its supossed to have.

    I suspect that i am doing something wrong but dont know what.

    Thanks in advance! (and sorry for my english)

    Delete this, wrong subforum, sorry.
    Last edited by fedegar33; 2 Nov 2011 at 10:04 AM. Reason: Delete post, wrong subforum

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Vote Rating
    1272
      0  

    Default

    I have moved to the appropriate forum.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •