Sticky Header In DataTable Disable Filters

UI Components for JSF
Post Reply
ar1376
Posts: 16
Joined: 26 Aug 2018, 10:09

10 Jul 2023, 16:26

Hi
I'm Using Primefaces 11 and 12

I'm Using

Code: Select all

stickyHeader="true"
tag in my

Code: Select all

<p:dataTable
and It work fine till I add a custom CSS :

Code: Select all

@media (min-width: 768px) {
    .ui-datatable table {
        width: 100% !important;
    }
}

@media (max-width: 769px) {
    .ui-datatable table {
        width: auto !important;
    }

    body .ui-datatable.ui-datatable-sticky > table > thead, body .ui-datatable.ui-datatable-sticky > table > tfoot {
        display: none;
    }
}
because in mobile users can't see columns and I should change width value that it make table scrollable
and I have to make sticky header's display as none because it won't scroll
and now the real table header's filters field (input text or selectOneMenu ...) are set as disabled
so I can't use filter

Image

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

11 Jul 2023, 19:56

PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

ar1376
Posts: 16
Joined: 26 Aug 2018, 10:09

12 Jul 2023, 10:38

Melloware wrote:
11 Jul 2023, 19:56
I think your issue is this: https://github.com/primefaces/primefaces/issues/3847
I didn't find any solution.
it seems that I need to customize primefaces code that don't disable the fields
well I don't know how yet
btw I'm using Diamond and Harmony template

UPDATE :
in datatable.js :
there is a function named as "setupStickyHeader" that in last line doing this :
this.clone.find('.ui-column-filter').prop('disabled', true);
and I have no idea how to customize this

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

12 Jul 2023, 14:09

That is done on purpose to the "sticky" header so as its stuck on the screen it can't be filtered. This is done on purpose only on the Sticky version of the header while you are scrolling right?
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

ar1376
Posts: 16
Joined: 26 Aug 2018, 10:09

15 Aug 2023, 17:01

Melloware wrote:
12 Jul 2023, 14:09
That is done on purpose to the "sticky" header so as its stuck on the screen it can't be filtered. This is done on purpose only on the Sticky version of the header while you are scrolling right?
There are Two headers when I Use Sticky Header , first one is the real header and the second one is the Sticky Header that Scroll down with it that it's on the first one, so you can't see the first one
but if I set the Sticky Header "display:none" then you can see the first header
but the problem is the filters are disabled !
I want my users be able to filter the column with first header too!
I put the code of primefaces on my last post that disable the fields

how can I customize "datatable.js" to solve the problem ?

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

15 Aug 2023, 17:10

You will have to analyze the datatable.js code and hack around.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

nehakakar
Posts: 5
Joined: 04 Jul 2023, 12:41
Location: India
Contact:

16 Aug 2023, 21:43

You can try the following Steps...
Instead of using the media query to set display: none for the sticky header on smaller screens,
You can try adjusting the position and z-index properties to ensure the sticky header still functions properly while being hidden visually.
Exa:

Code: Select all

@media (max-width: 769px) {
    .ui-datatable.ui-datatable-sticky > table > thead, .ui-datatable.ui-datatable-sticky > table > tfoot {
        position: absolute;
        top: -9999px;
        z-index: -1;
    }
}
If this not work try using this method.
You could modify the sticky header's visibility instead of using display: none. This might allow the filters to remain active.
Ex:

Code: Select all

@media (max-width: 769px) {
    .ui-datatable.ui-datatable-sticky > table > thead, .ui-datatable.ui-datatable-sticky > table > tfoot {
        visibility: hidden;
    }
}
If necessary, you can conditionally apply your custom styles based on the presence of the .ui-datatable-sticky class.
his way, you can control the styling only when sticky headers are active.
Ex:

Code: Select all

.ui-datatable-sticky {
    /* Sticky header styles */
}

.ui-datatable-sticky > table > thead {
    /* Sticky header visibility adjustments */
}
note: Always thoroughly test your changes across different screen sizes and ensure that the desired functionality,

Clarar
Posts: 2
Joined: 17 Aug 2023, 05:14

18 Aug 2023, 07:31

Melloware wrote:
12 Jul 2023, 14:09
That is done on purpose to the "sticky" header so as its stuck on the screen it can't be filtered. This is done on purpose only on the Sticky version of the header while you are scrolling right?
Hi friend
Absolutely, intentional design! The "sticky" header stays fixed, preventing unintended filtering while scrolling.Free Fire name style
Last edited by Clarar on 20 Aug 2023, 13:27, edited 1 time in total.

Clarar
Posts: 2
Joined: 17 Aug 2023, 05:14

20 Aug 2023, 13:27

Hello guys

Struggling with disabling filters in a DataTable's sticky header? Feel free to ask for guidance.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 14 guests