tags:

views:

827

answers:

4

The handler of an extjsAction button calls a function with 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 works only on the first button click. does ot disable the row which gets added.

A: 

I will edit my response with an appropriate answer once supplied more information.

When are you firing getRowClass? It seems like you are creating the function but never actually calling to for a response.

Does the function error out, get called at all, or just doesn't do what you want?

Ballsacian1
+2  A: 

getRowClass only needs to be assigned one time. It is not a function that you call, it is a function called internally by the grid every time a row is rendered. Rather than assigning it inside an event handling function, it should be assigned ONE time, somewhere at the application level (e.g., wherever Grid1 itself is first configured would be the most logical place). This may or may not be your issue, depending on how your Add function is getting called, which is not clear. Bear in mind that since you rely on IDList inside getRowClass, you'll also have to have a reference to that variable that is in scope where the function is, and you will probably also have to add checks to make sure it is valid before accessing it.

You are also not showing where Grid1 is getting re-rendered. As explained above, getRowClass only executes when rows are rendered, so unless you are refreshing Grid1 somewhere not shown in your code, getRowClass will never be called.

bmoeskau
This is true. getRowClass get executed only on (re)render. I think the store reload (called at function beginning) should do grid refresh, but only in case the data has changed (internal adds doesn't count).It's also unclear whether `window.items.items[0].getStore()` and `Ext.getCmp('grid2').getStore()` return the same store.
Thevs
Yes, the getRowClass was getting called only once when the grid was configured. And I needed something which would get fired each time the window.show event fires. So I used the code below in onWindowShow 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') } }
A: 

Yes, the getRowClass gets called only once when the grid is configured. But i wanted something that would fire everytimewindow.show() gets fired. 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')
            }
        }
A: 

FYI, while I'm glad that you found a solution that works for you, I'm not sure you understand getRowClass still. It does NOT get called only once -- it gets called EVERY time a grid row is re-rendered (which is anytime data changes). It was only getting called once in YOUR code because your code was not set up correctly.

I don't fully understand your use case, but regardless of the window being shown, the row striping would only need to change if the grid's underlying data actually changed. When you set up the getRowClass function properly, the grid takes care of calling it for you automatically, when it needs to, and it should "just work." There should be no need for your iteration code as written which just adds extra overhead.

Again, just FYI. :)

bmoeskau
Well, the row striping on Grid1 actually depended on the data change in another grid. In my case, Idlist is the one that changes and depending on that the row class in my grid1 changes.
I would still think that you would simply bind Grid1 to whatever underlying store is managing the data, even if it is changed in another grid. That way the updates and calls to getRowClass are done for you as expected without the need for manual processing. But again, if you have a solution that works for you, that's what matters most.
bmoeskau