3

I have a webapp, which uses JQGrid table and I would like to freeze the rownum column just like any other column but I can't because there's no access to the rownum colModel and it's impossible to set freeze: trueproperty of a rownum.

Here's my JSFiddle with a working example, which is correct, except that it freezes both rownum and Inv No columns and I would like to freeze only the first column. To check the column freeze: just resize the JSFiddle window in such way that a table get's horizontal scrollbar and reload the fiddle.

Does anyone know how to achieve this? Every useful answer (especially JSFiddle) is highly appreciated and evaluated.

Thank you.

amenoire
  • 1,892
  • 6
  • 21
  • 34

1 Answers1

1

I find your suggestion interesting. jqGrid don't allows to make "rn" (created in case of the usage of rownumbers: true option) or "cb" (created in case of the usage of multiselect: true option) columns frozen. As you probably know I develop my fork of jqGrid since last 4 month under the name free jqGrid (see readme and wiki for more details). So I just made the corresponding changes in the code of setFrozenColumns in my fork.

The demo demonstrates the feature. The columns "rn" and "cb" have frozen: true column by default. So one need just call setFrozenColumns method to make there frozen:

enter image description here

An additional problem with frozen columns is the position and the height of individual rows if not all rows have the same height. For example inline editing can increase the height of row. I fixed the problem too.

The next demo uses frozen column with formatter: "action" and the "rownumber" column ("rn" column). One can see that the height of frozen rows will be automatically adjusted on the start or the end of inline editing:

enter image description here

So you need just download the latest code of free jqGrid from GitHub to solve your problem.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • if jqgrid has parameter `sortable: function (permutation) { saveWindowState(); },` actions column is not frozen. How to allow remember column order and froze actions column if it is first column ?. Actions column is usually first column always so froze should work in this case also. If action column is not first, froze should not work only in this case. – Andrus Apr 23 '15 at 15:35
  • @Andrus: Only **the first columns** of the grid can be frozen. The current implementation don't allow to set last columns as frozen. `sortable` option can't be used with frozen columns too (see [the limitations](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:frozencolumns#limitations) in the documentation) – Oleg Apr 23 '15 at 15:48
  • @Andrus: By the way, did you seen that there are exist now `remapColumnsByName` method additionally to `remapColumns` and I improved performance of both? So one can save now the list of column names as the part of "the state" of the grid and to use `remapColumnsByName` method in `restoreWindowState`. – Oleg Apr 23 '15 at 16:31
  • actions column is always first after multiselect column. Column order needs also be saved so `sortable` property must filled. Unfortunately setFrozenColumns works only if sortable is not specified. How to allow to froze actions and multiselect columns in this case ? Maybe some other propery instead of sortable can used to remember column order if changed by user by dragging or other way? – Andrus Apr 23 '15 at 16:36
  • Is there some sample how to save and restore column order and widths by name? – Andrus Apr 23 '15 at 16:39
  • @Andrus: If I understand you correctly then you misunderstand the meaning of the option `sortable`. It's needed to allow to change the order of columns using drag&drop of column headers. It uses internally `sortableColumns` method. One can modify the code of `sortableColumns` to work with frozen columns, but it need time. You can post it to issue as feature request. You can make first columns added by `multiselect: true` and `rownumber: true` frozen if you use last code of free jqGrid from github. – Oleg Apr 23 '15 at 16:46
  • @Andrus: The usage of `remapColumnsByName` very simple you can get the names of colums and save there in array of strings: ["aa", "bb", "cc"] . You can change the order of the columns by call `$("#grid").jqGrid("remapColumnsByName", ["bb", "aa", "cc"], true);`. If you want to save and later to restore the columns then it would be more effective to reorder `colModel` items and `colNams` items **before** the grid will be created. So you will be not need to use neither `remapColumnsByName` nor `remapColumns` methods of grid. – Oleg Apr 23 '15 at 16:55
  • I posted it in https://github.com/free-jqgrid/jqGrid/issues/52 We discussed it 3 years ago in http://www.trirand.com/blog/?page_id=393/bugs/frozen-column-impressions – Andrus Apr 23 '15 at 17:34