J Bourne
J Bourne

Reputation: 1429

Jqgrid: how to change a formatter dynamically?

My Jqgrid problem is little unique. I've said, I do a after loadComplete I show some of the editable rows as

$("#correction-grid").editRow(rowid, true);

But I don't want this to happen for certain coloumns if one of its coloumn value happens to be 'miscelleaneous' so I tried this

 loadComplete: function (rowid, status) {
   $("#correction-grid > tbody > tr").each(function (rowid) {
   $("#correction-grid").editRow(rowid, true);
   var value = $('#correction-grid').jqGrid('getCell',rowid,'product_group_code');
   console.log(value)
   if(value == 'MISC'){
    $('#correction-grid').setColProp('x_code',{edittype:false}); 
        $('#correction-grid').setColProp('yr_code',{edittype:false}); 
        $('#correction-grid').setColProp('diesel',{edittype:false}); 
            }
          });

where x_code happens to be a select box with a dataEvents, while yr_code and diesel are formatted as text value. If I'm trying to apply this logic in formmaters, all the rows are becoming readable only fields. So I tried at loadComplete. Any ideas or suggestion would be of great help..!

Thank You Sai

Upvotes: 1

Views: 2256

Answers (1)

Oleg
Oleg

Reputation: 221997

I suppose your error is that you call editRow before changing of the edittype property and that you don't reset the value to true in case of value !== 'MISC'. You can fix the code so:

loadComplete: function () {
    var $this = $(this);    // $("#correction-grid")
    $("> tbody > tr", this).each(function (rowid) {
        var product_group_code = $this.jqGrid('getCell', rowid, 'product_group_code'),
            isEditable = product_group_code !== 'MISC';
        console.log(product_group_code);
        $this.setColProp('x_code', {edittype: isEditable});
        $this.setColProp('yr_code', {edittype: isEditable});
        $this.setColProp('diesel', {edittype: isEditable});
        $this.editRow(rowid, true);
    });
}

Upvotes: 1

Related Questions