Extjs : How to enable/disable a checkbox using renderer while loading a grid

穿精又带淫゛_ 提交于 2019-12-10 17:35:24

问题


I need to load a grid based on the query results I get. I am not having any issues with loading the text fields in the grid but there is one particular column which is a check box type. I am using the xtype: 'checkcolumn' for this purpose. The object that returns the query results returns a "Y" or "N" for this particluar column. If it is "Y", I need to enable the checkbox and if it is "N", the checkbox should be disabled. I am using the following code for defining my checkbox field.

 {
        xtype: 'checkcolumn',
        header: "Old User",
        disabled: true,
        disabledCls:'x-item-enabled',
        width: 170,
        dataIndex: 'oldUser',
        itemId: 'oldUser',
        renderer: this.checkOldUser
 }      

checkOldUser: function (oldUser) {
        if(oldUser== 'Y'){
              this.oldUser.setDisabled(false);
        }
    }

This renderer function is not working for me. How should the renderer look like?. Can you please let me know how to resolve this issue?. Thanks....


回答1:


Wow, I thought this would be easier, but as it turns out.... not so much..

You will have to do two things:

1 - Change your checkcolumn renderer

2 - Add a beforecheckchange listener to return false in case the user clicks on a record that has 'N' as value;

Your final grid should look something like this:

Ext.create('Ext.grid.Panel', {
    height: 250,
    width: 579,
    title: 'My Grid Panel',
    defaultListenerScope: true,
    store: myStore,
    columns: [
        {
            xtype: 'gridcolumn',
            dataIndex: 'name',
            text: 'Name'
        },
        {
            xtype: 'checkcolumn',
            renderer: function(value, metaData, record, rowIndex, colIndex, store, view) {
                var cssPrefix = Ext.baseCSSPrefix,
                    cls = cssPrefix + 'grid-checkcolumn';


                if (this.disabled || value == 'N') {
                    metaData.tdCls += ' ' + this.disabledCls;
                }
                if (value) {
                    cls += ' ' + cssPrefix + 'grid-checkcolumn-checked';
                }

                return '<img class="' + cls + '" src="' + Ext.BLANK_IMAGE_URL + '"/>';
            },
            dataIndex: 'oldUser',
            text: 'OldUser',
            listeners: {
                beforecheckchange: 'onCheckcolumnBeforeCheckChange'
            }
        }
    ],

    onCheckcolumnBeforeCheckChange: function(checkcolumn, rowIndex, checked, eOpts) {
        var row = this.getView().getRow(rowIndex),
            record = this.getView().getRecord(row);
        return (record.get('oldUser') != 'N');
    }
});

I created a Fiddle: https://fiddle.sencha.com/#fiddle/bqd




回答2:


Slightly simpler way helped me

           renderer: function(val, metaData, rec) {

              if (rec.get('usersSetId') == -1) {
                metaData.tdCls += ' ' + this.disabledCls;
              }

              return (new Ext.ux.CheckColumn()).renderer(val, metaData);

            },
            listeners: {
              beforecheckchange: function (the, rowIndex, checked, eOpts) {
                var record = the.up('grid').getStore().getAt(rowIndex);
                return (record.get('usersSetId') != -1);
              }
            }



回答3:


renderer: function(value, metaData, record, rowIndex, colIndex, store, view) {         

if(record.data.taskStatus == 'Success' || record.data.acknowledgeBak == true){ 
    metaData.css = " x-item-disabled"; 
  }
  return (new Ext.grid.column.CheckColumn).renderer(value);
  },
  listeners: {
  beforecheckchange: function (the, rowIndex, checked, eOpts) {
    var record = the.up('grid').getStore().getAt(rowIndex);
    return (record.get('taskStatus') != "Success" && record.get("acknowledgeBak") != true);
  }
},


来源:https://stackoverflow.com/questions/26370392/extjs-how-to-enable-disable-a-checkbox-using-renderer-while-loading-a-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!