Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Column Freeze or Fixed Column in datatable

Tags:

primefaces

Is it possible to freeze first 3 columns of Primefaces' data table?

I'm using Primefaces 3.1

like image 920
Shikha Dhawan Avatar asked May 18 '12 10:05

Shikha Dhawan


People also ask

How to set fixed column in DataTable?

FixedColumns allows columns to be fixed from both the left and the right hand sides of the table. Fixing right hand-side columns is done by using the fixedColumns. right initialisation parameter, which works just the same as fixedColumns. left does for the left side of the table.

What is FixedColumns in Datatables?

FixedColumns provides the option to freeze one or more columns to the left or right of a horizontally scrolling DataTable. This allows information in the fixed columns to remain visible even when scrolling through the data set. This can be particularly useful if you wish to show a large number of columns.

What is scroll collapse in DataTable?

The DataTable also exposes a powerful API that can be further used to modify how the data is displayed. The scrollCollapse option is used to specify whether the table will collapse when the scrollY option is used to determine the maximum height of the table.


2 Answers

Primefaces does not support fixed columns right now.

Jquery fixed column was used to achieve the same. Reference : http://datatables.net/extras/fixedcolumns/

Example:

var oTable2 = $(primfacesDataTableId).find('table').dataTable({
                "sScrollX" : "100%", //Scroll
                "sScrollY" : "180",
                "bAutoWidth" : false,
                "bScrollCollapse" : true,
                "bPaginate" : false,
                "bSort" : false,
                "sInfo" : "",
                "sInfoEmpty" : ""
            });

var oFC = new FixedColumns(oTable2, {
                    "iLeftColumns" : 4, //Freezed first for columns
                    "sHeightMatch" : "auto",
                    "iLeftWidth" : 405
                });

Thanks, Shikha

like image 145
Shikha Dhawan Avatar answered Jan 04 '23 11:01

Shikha Dhawan


For those who are using Primefaces 4.1 or above, this feature is now implemented (it took four years from the first request, by the way):

https://code.google.com/p/primefaces/issues/detail?id=366

You can play with the horizontal scrolling in the showcase.

like image 31
Xtreme Biker Avatar answered Jan 04 '23 10:01

Xtreme Biker