1

Please guide me on a work around for having a set of columns frozen and the rest having cell edit feature along with column reordering/ show- hide options using jqgrid.

Thank You.

  • http://www.trirand.com/jqgridwiki/doku.php?id=wiki:frozencolumns – Runcorn Feb 10 '15 at 07:20
  • Do you need to edit some frozen columns or only the columns which have no `frozen:true` property? – Oleg Feb 10 '15 at 10:56
  • @Oleg - I need to edit only non frozen columns but these non frozen columns need to be reordered or show/hide as well. – user3759787 Feb 11 '15 at 04:48
  • @Runcorn - Thank you but I had already seen the site that you mentioned. I am unable to figure out despite the current limitation of jqgrid - frozen columns not working with reordering of non frozen columns, is there any possibility of incorporating it or should I switch over to other grid solutions. – user3759787 Feb 11 '15 at 04:52

2 Answers2

1

Please try this, simple solution,

Hide or remove cellEdit: true

Then add the below lines in above and below the setFrozenColumns

Previous code:

 $("#jqGrid2").jqGrid('setFrozenColumns');

New Code:

$("#jqGrid2").jqGrid("setGridParam", {cellEdit: false, sortable: false});
$("#jqGrid2").jqGrid('setFrozenColumns');
$("#jqGrid2").jqGrid("setGridParam", {cellEdit: true, sortable: true});
bgs
  • 3,061
  • 7
  • 40
  • 58
0

The problem is that the current implementation of setFrozenColumns have some restrictions. Editing (in any editing mode) and sortable: true is not allowed for frozen columns, but setFrozenColumns. Moreover sortable: true should don't allow to resort headers of frozen columns. On the other side setFrozenColumns contains simple test of some parameters (see here) and the method do nothing if some such parameters (like cellEdit or sortable) are set.

I suggested in the post (with the demo) the way how to implement a workaround. The way is modification of approach from the answer and this one.

I find your question interesting and so I created the demo which demonstrates how one do can implement your requirements. It displays the following results (animated gif):

enter image description here

It uses mostly the following code

// create the grid
$grid.jqGrid({
    ...
});

$grid.bind("jqGridLoadComplete jqGridInlineEditRow jqGridAfterEditCell jqGridAfterRestoreCell jqGridInlineAfterRestoreRow jqGridAfterSaveCell jqGridInlineAfterSaveRow", function () {
    fixPositionsOfFrozenDivs.call(this);
});

$grid.jqGrid("setGridParam", {cellEdit: false, sortable: false});
$grid.jqGrid("setFrozenColumns");
$grid.jqGrid("setGridParam", {cellEdit: true, sortable: true});
fixPositionsOfFrozenDivs.call($grid[0]);

try {
    var p = $grid.jqGrid("getGridParam"), tid = $.jgrid.jqID(p.id), colModel = p.colModel, i, n = colModel.length, cm,
        skipIds = [];

    for (i = 0; i < n; i++) {
        cm = colModel[i];
        if ($.inArray(cm.name, ["cb", "rn", "subgrid"]) >=0 || cm.frozen) {
            skipIds.push("#jqgh_" + tid + "_" + $.jgrid.jqID(cm.name));
        }
    }

    $grid.jqGrid("setGridParam", {sortable: {options: {
        items: skipIds.length > 0 ? ">th:not(:has(" + skipIds.join(",") + "),:hidden)" : ">th:not(:hidden)"
    }}});

    $grid.jqGrid("sortableColumns", $($grid[0].grid.hDiv).find(".ui-jqgrid-labels"));
} catch (e) {}
Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • @Oleg- Thank you so much. I am novice when it comes to jqgrid and I find many of your posts very useful. Still struggling to make the most out of it. I am unable to correlate items like bDiv, cDiv, hDiv, fbDiv, fhDiv, uDiv which was mentioned in one of your answers. Trying out things like enabling/disabling rows based on condition on load of jqgrid, enabling/disabling columns based on condition again on load of jqgrid, in line cell editing based on conditions, adding new row with value even for frozen column, all in the same jqgrid. Shall keep you posted. Thanks once again! – user3759787 Feb 12 '15 at 11:32