jQWidgets Forums

jQuery UI Widgets Forums Grid cellrenderer

This topic contains 2 replies, has 2 voices, and was last updated by  atomic 7 years, 11 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    cellrenderer Posts
  • cellrenderer #94309

    atomic
    Participant

    Hi guys,

    I would like to make some JQXGrid cells not editable based on values (null), and I was able to do it with cellbeginedit: isEditable

        $("#jqxGrid").jqxGrid({
            height: 750,
            width: '100%',
            theme: theme,
            source: dataAdapter,
            editable: true,
            columnsresize:true,
            selectionmode: 'multiplecellsadvanced',
            columns: [
                      {text: '', datafield:'item',  pinned: true, editable: false},    
                      {text: 'unit', datafield:'unit', pinned: true, editable: false }, 
                      {text: 'PWR', datafield:'PWR', cellsformat: 'd4', cellsrenderer: cellsrenderer, cellbeginedit: isEditable  }, 
                      {text: 'HWR', datafield:'HWR', cellsformat: 'd4', cellsrenderer: cellsrenderer, cellbeginedit: isEditable  },    
                      {text: 'FPP', datafield:'FPP', cellsformat: 'd4', cellsrenderer: cellsrenderer, cellbeginedit: isEditable  }
                ]             
        }); 
    
        var isEditable = function (row, column) {
            var value = $('#jqxGrid').jqxGrid('getcellvalue', row, column);
            if (value == null)
                return false;
        }
    

    So far everything works fine, but I would like to render these, not editable cells, a little bit different, so I introduced cellrenderer function.

        var cellsrenderer = function (row, columnfield, value, defaulthtml, columnproperties) {
            if(value == null){
                 return '<span style="margin: 4px; float:right; color: #f0ad4e; font-weight:bold" >n/a</span>';
            }
        }
    

    but things are not working correctly since the value passed to cellrenderer function is not null anymore but zero (return false in isEditable function probably changed the value) 🙁 . Is there a way to make cell not editable based on value and still apply custom rendering?

    Thank you.

    cellrenderer #94338

    Hristo
    Participant

    Hello atomic,

    Please, take a look at this topic, it could be helpful:
    http://www.jqwidgets.com/community/topic/allow-cells-to-be-editable-only-under-specific-conditions
    I would suggest you use an additional hidden column and this will determinate your logic (in cellsrenderer).
    Another option is to use null as a string. Possible values: ‘string’, ‘date’, ‘number’, ‘float’, ‘int’ and ‘bool’ for the type of the datafields and if you do not choose one of them the DataAdapter will set one of them (suitable for the case).
    In your case, it set as a string but with an empty value and for that reason it never goes into your case.

    Best Regards,
    Hristo Hristov

    jQWidgets team
    http://www.jqwidgets.com

    cellrenderer #94356

    atomic
    Participant

    Hello Hristo,

    Setting null value as a string (null => “null”) in source json file did the job. Yeah it is obvious now 🙂
    Thank you very much for reply and help.
    Best regards

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.