Sencha-Extjs-如何从控制器动态使用网格getRowClass()

Sencha Extjs - How to use grid getRowClass() dynamically from Controller

本文关键字:网格 getRowClass 动态 控制器 Sencha-Extjs-      更新时间:2023-09-26

我的网格中有一个复选框列,根据复选框的选择显示是/否。

要求:如果复选框值==是,则将行颜色更改为绿色Else保持原样(默认)。

到目前为止我已采取的步骤:在Ext.grid.View上设置getRowClass函数,如下所示:

 viewConfig: {
 getRowClass: function(record, rowIndex, rowParams, store) {
 if (record.get('isApproved') == true)
   {
     return 'highlight-rowgreen';
   }                           
 },

这非常好用然而,我想在store.sync回调中实现这一点,但目前还没有实现。没有错误,什么都没有。就是不起作用。

var store = Ext.getStore('MyApp.MyStore');
        store.proxy.url = MYAPP.globals.url + "myapplication/" + branchNo + "/event/" + branchEventId;
        store.sync({
            scope: this,
            callback:function (records, operation, success) {
                if(records.proxy.reader.rawData.success){
                // Success. Set the rows color to green if not already done.                    
                   alert('Update Completed');
                   eventsGrid.getView().getRowClass = function(record, rowIndex, rowParams, store){
                       console.log('I am here');
                       if (record.get('isApproved') == true)
                       {
                        return 'highlight-rowgreen';
                       }
                      };
                  }
                  else{
                     alert('Update failed');                   
                  }
                }
        });

我看不到的是我的控制台日志"我在这里"。我可以看到警报消息。

我也尝试过其他类似的解决方案,但没有成功。

感谢您的帮助。感谢

您不需要在存储同步回调中再次设置rowclass。它应该正常工作。可能是你的网格视图需要刷新。试试这个。。

 store.sync({
        scope: this,
        callback:function (records, operation, success) {
            if(records.proxy.reader.rawData.success){
            // Success. Set the rows color to green if not already done.                    
               alert('Update Completed');
               eventsGrid.getView().refresh(); //refresh grid view
              }
              else{
                 alert('Update failed');                   
              }
            }
    });