2

Is there any way, in cell editing, to change the edittype of a cell when it is being edited (if certain conditions are met)?

Supposse I have a colModel that has a field "Description", which by default is going to be treated as an input. When I click to edit in that cell, and input is going to appear with the current cell value. Now, if certain condition is met, I'd like that when the user clicks that cell to edit it, instead of an input a select appears.

I've tried using setColProp and changing both the edittype and the editoptions, but either I haven't done so in the right place (I did it in the beforeCellEdit event), or it doesn't work that way.

Thanks.

UPD:

I have tried to use the strategy you proposed, but my cell still shows an input after I invoke the setColProp method:

var originalEditCell = $.fn.jqGrid.editCell;

    $.jgrid.extend({
        editCell: function (iRow, iCol, isStartEditing) {

            if (iCol === 4 && classEditMode) {

                $(this).jqGrid('setColProp', "ColName4", { edittype: "text" });
                var cell = $(this).find('tr:eq(' + iRow + ')').find('td[aria-describedby="gridFix_Description"]');
                cell.find('select').remove();
                cell.append($('<input />').attr('id', iRow + '_Description')
                                          .attr('name', 'Description')
                                          .attr('role', 'textbox')
                                          .width('98%')
                                          .text(""));
            }
            return originalEditCell.call(this, iRow, iCol, isStartEditing);
        }
    });

The grid still generates a select. Any idea why?

Thanks

UPD2

Sorry, I had forgotten to include the correct variable for the colname in the setColProp method. I corrected that in the post to keep record of how I solved this issue if somebody else needs it.

Thanks.

Heathcliff
  • 3,048
  • 4
  • 25
  • 44

1 Answers1

1

You can use onCellSelect callback or beforeSelectRow to manage the case of dynamical changing of some properties before editCell will be called. The problem is only that it will don't help in case of keyboar navigation.

As a safe workaround, but a little tricky, I can suggest to use "subclasing" of jqGrid method editCell (see here, here etc). The corresponding code fragment will be the following

var originalEditCell = $.fn.jqGrid.editCell;

$.jgrid.extend({
editCell: function (iRow, iCol, isStartEditing) {
        // here you can do some actions before editing
        return originalEditCell.call(this, (iRow, iCol, isStartEditing);
    }
});
Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798