Freeze rownum column in JQGrid
Asked Answered
B

1

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.

Beaut answered 23/4, 2015 at 10:7 Comment(1)
I've changed the JSFiddle link, so please check it once more for a working example.Beaut
O
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.

Ofeliaofella answered 23/4, 2015 at 14:5 Comment(8)
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.Barnhill
@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 in the documentation)Ofeliaofella
@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.Ofeliaofella
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?Barnhill
Is there some sample how to save and restore column order and widths by name?Barnhill
@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.Ofeliaofella
@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.Ofeliaofella
I posted it in github.com/free-jqgrid/jqGrid/issues/52 We discussed it 3 years ago in trirand.com/blog/?page_id=393/bugs/frozen-column-impressionsBarnhill

© 2022 - 2024 — McMap. All rights reserved.