Sticky Header

Locked
calin74
Posts: 28
Joined: 01 Jul 2014, 10:35

21 Mar 2015, 14:30

Hi,

ich have the option stickyHeader="true" on my DataTable.
But on scrolling, the topbar hides the table header.

Thank your for your Help.
Chris
Last edited by calin74 on 26 Mar 2015, 05:45, edited 1 time in total.

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

23 Mar 2015, 10:55

I think you can override setupStickyHeader function.

Code: Select all

 <ui:define name="head">
        <script type="text/javascript">
//<![CDATA[
//@Override
PrimeFaces.widget.DataTable.prototype.setupStickyHeader = function() {
    var table = this.thead.parent(),
        offset = table.offset(),
        win = $(window),
        $this = this,
        stickyNS = 'scroll.' + this.id,
        resizeNS = 'resize.sticky-' + this.id,
        layoutHeaderHeight = $('#layout-header').height();  // added the height of layout header.

        this.cloneContainer = $('<div class="ui-datatable ui-datatable-sticky ui-widget"><table></table></div>');
        this.clone = this.thead.clone(true);
        this.cloneContainer.children('table').append(this.clone);
        
        this.cloneContainer.css({
            position: 'absolute',
            width: table.outerWidth(),
            top: offset.top,
            left: offset.left,
            'z-index': ++PrimeFaces.zindex
        })
        .appendTo(this.jq);

        win.off(stickyNS).on(stickyNS, function() {
            var scrollTop = win.scrollTop(),
            tableOffset = table.offset();
            
            if(scrollTop > tableOffset.top) { 
                $this.cloneContainer.css('top', scrollTop + layoutHeaderHeight)
                                    .addClass('ui-shadow ui-sticky');

                if(scrollTop >= (tableOffset.top + $this.tbody.height())) {
                    $this.cloneContainer.hide();
                }
                else {
                    
                    $this.cloneContainer.show();
                }
            }
            else {
                $this.cloneContainer.css('top', tableOffset.top)
                                    .removeClass('ui-shadow ui-sticky');
            }
        })
        .off(resizeNS).on(resizeNS, function() {
            $this.cloneContainer.width(table.outerWidth());
        });
        
        //filter support
        this.thead.find('.ui-column-filter').prop('disabled', true);
};
//]]>
        </script>
    </ui:define>

calin74
Posts: 28
Joined: 01 Jul 2014, 10:35

25 Mar 2015, 14:44

Thank you for your answer.

This is working, but its hard to maintain for future primefaces versions.
I wonder if there is no property to define the min top position.

What is also not working (and this is the worst problem):
- Resize the left-menu from sentinel layout does also not resize the sticky header correct.

It seems, this was not testet for the sentinel-layout :cry:

Greeting
Chris

calin74
Posts: 28
Joined: 01 Jul 2014, 10:35

25 Mar 2015, 15:27

I added the following line

Code: Select all

$this.cloneContainer.css('left', table.offset().left);
to the method

Code: Select all

.off(resizeNS).on(resizeNS, function() { ...
so the code is

Code: Select all

.off(resizeNS).on(resizeNS, function() {
    $this.cloneContainer.width(table.outerWidth());
    $this.cloneContainer.css('left', table.offset().left);
});
So on next primefaces updates i always have to check this method - this is the only bad thing :?

calin74
Posts: 28
Joined: 01 Jul 2014, 10:35

26 Mar 2015, 06:21

Another problems with the sticky table header:

- Resize the left-menu does not refresh the sticky table header
Image

- If i display one or more error messages, the table moves down (because of the space for the error message)
But the sticky table header stays positioned.
Image

Thanks for helping

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

26 Mar 2015, 11:01

StickyHeader is not fully compatible with a layout like Sentinel, due to conflicts with top bar and the left menu as you've mentioned. There is no generic solution we are aware of. StickyHeader for example cannot know if left menu of Sentinel is toggled. Also top menu is fixed which conflicts with whole sticky header design as it is also fixed.

calin74
Posts: 28
Joined: 01 Jul 2014, 10:35

01 Apr 2015, 13:42

Thanks for your answer.

spadinha
Posts: 15
Joined: 17 Apr 2015, 00:23

07 Nov 2016, 16:34

Thaks for this post.. it helped me to solve the problem with sentinel sticky

I did some adjusts on funcion... and its working...

Code: Select all

<script type="text/javascript">
			//<![CDATA[
			//@Override
			PrimeFaces.widget.DataTable.prototype.setupStickyHeader = function() {
				var table = this.thead.parent(), offset = table.offset(), win = $(window), $this = this, stickyNS = 'scroll.'
						+ this.id, resizeNS = 'resize.sticky-' + this.id, layoutHeaderHeight = $(
						'#layout-header').height();

				this.cloneContainer = $('<div class="ui-datatable ui-datatable-sticky ui-widget"><table></table></div>');
				this.clone = this.thead.clone(true);
				this.cloneContainer.children('table').append(this.clone);
				this.cloneContainer.hide();

				this.cloneContainer.css({
					position : 'absolute',
					top : offset.top,
					'z-index' : ++PrimeFaces.zindex
				}).appendTo(this.jq);

				win
						.off(stickyNS)
						.on(
								stickyNS,
								function() {
									var scrollTop = win.scrollTop(), tableOffset = table
											.offset();

									if (scrollTop > tableOffset.top) {
										$this.cloneContainer.css('top',
												scrollTop - 45).addClass(
												'ui-shadow ui-sticky');

										if (scrollTop >= (tableOffset.top + $this.tbody
												.height())) {
											$this.cloneContainer.hide();
										} else {

											$this.cloneContainer.show();
										}
									} else {
										$this.cloneContainer.css('top',
												scrollTop - 45).removeClass(
												'ui-shadow ui-sticky');

										$this.cloneContainer.hide();
									}
								}).off(resizeNS).on(resizeNS, function() {
							$this.cloneContainer.width(table.outerWidth());
						});

				//filter support
				this.thead.find('.ui-column-filter').prop('disabled', true);
			};
			//]]>
		</script>
Last edited by spadinha on 26 Aug 2017, 03:06, edited 1 time in total.

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

15 Nov 2016, 14:39

Glad to hear, thanks for the update!

Locked

Return to “Sentinel”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 11 guests