ExtjsGirdPanel.getView (). getRowClass doesn't work 2nd time

The extjsAction button handler calls a function with the following code.

  Add: function() {
        var window = Ext.getCmp('wndAdd');
        window.items.items[0].getStore().reload;
        var Grid1 = Ext.getCmp('grdAll');

        var grdStore2 = Ext.getCmp('grid2').getStore();
        var i = 0;
        var IDList = new Array();
        for (i = 0; i < grdStore2.data.length; i++) {

               IDList[i] =
               grdStore2.data.items[i].data['ID'];

        }

        Grid1.getView().getRowClass = function(record, index) {

            if (IDList.contains(record.data["ID"])) {
                return 'disabled-row';
            }
        };

        window.show();

    }

      

But the getRowClass function only works the first time the button is pressed. disables the line that is being added.

0


a source to share


4 answers


Yes, getRowClass is only called once when the grid is set up. But I wanted something that could work every trick. I used the below code on window.onshow event.



for (var i = 0; i < Grid1.getStore().data.length; i++) {
    var element = Ext.get(Grid1.getView().getRow(i));
    var record = Grid1.getStore().getAt(i);
    if (IdList.contains(record.data.ID)) {
        element.addClass('disabled-row')
    } else {
        element.removeClass('disabled-row')
    }
}

      

+1


a source


getRowClass only needs to be assigned once. This is not a function that you are calling, it is a function called internally by the net every time a string is displayed. Instead of assigning it inside the event handling function, it should be assigned ONE time, somewhere at the application level (for example, wherever the first configuration of Grid1 would be the most logical place). This may or may not be your problem, depending on how the calling Add function is called, which is unclear. Keep in mind that since you are relying on the IDList inside getRowClass, you will also have to have a reference to that variable which is in the scope of the function, and you will probably also have to add checks to make sure they are valid before being accessed he.



You also don't show where Grid1 is getting re-rendered. As explained above, getRowClass is only executed when the rows are rendered, so unless you update Grid1 somewhere not shown in your code, getRowClass will never be called.

+2


a source


FYI, although I'm glad you found a solution that works for you, I'm not sure if you still understand getRowClass. It is NOT called just once - it gets the name EVERY time the grid row is re-rendered (this is a data change at any time). It was called only once in YOUR code because your code was not configured correctly.

I don't quite understand your use case, but regardless of the window displayed, the row bar should only change if the underlying grid data has actually changed. When you set up the getRowClass function correctly, the grid will take care of automatically naming it for you when needed, and it should "just work". There should be no need for your iterative code as written, which just adds additional overhead.

Again, just FYI. :)

+1


a source


I will edit my answer with the corresponding answer after providing more information.

When do you run getRowClass? It seems that you are creating a function, but you are not actually calling a response.

Is the function error being thrown, triggered at all, or just doesn't do what you want?

0


a source







All Articles