Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Horizontal Scroll Position Lost on Header Filter, Header Sort or Pagination Changes (only with Remote Pagination, Filter & Sort) #4494

Open
Anton-Plagemann opened this issue May 8, 2024 · 1 comment
Labels
Possible Bug A possible bug that needs investigation

Comments

@Anton-Plagemann
Copy link

Anton-Plagemann commented May 8, 2024

Describe the bug
Reopening #3450 as a new issue because the old one has been closed with a partial fix only.
The issue: The horizontal scrolling position gets lost when using header filters, header sorting, changing page size or changing page AND remote pagination/filtering/sorting is enabled. Additional details can be found in #3450.

Tabulator Info

  • v6.2.1

Working Example
Could not provide a working example with jsfiddle because a server is needed for remote pagination/sorting/filtering.

To Reproduce

  1. Create a table with remote pagination, filtering & sorting, e.g.
new Tabulator(tableHTMLElement, {
  pagination: true,
  paginationMode: "remote",
  filterMode: "remote",
  sortMode: "remote",
  ajaxURL: `https://example.com/getTableData`,
  columns: [
    {
      title: "Some column (repeat until a horizontal scrollbar appears)",
      field: "someRemoteField",
      headerFilter: "input",
    },
  ],
});
  1. Scroll to the right of the table.
  2. Click on a column header (sorting), enter a value into the header filter input, or switch to page 2.
  3. See the horizontal scrolling position reset to the most left position.

Expected behavior
The scroll position should not reset.

Desktop:

  • OS: Windows 11
  • Browser: Microsoft Edge (Chromium)
  • Version: 124.0.2478.80

Additional Info
I want to express my appreciation for the Tabulator package and the continuous efforts to improve it. The functionality it provides has been instrumental in developing complex but intuitive interfaces. Thank you for your dedication and hard work on maintaining such a valuable tool ❤️

@Anton-Plagemann Anton-Plagemann added the Possible Bug A possible bug that needs investigation label May 8, 2024
@Anton-Plagemann
Copy link
Author

Anton-Plagemann commented May 9, 2024

I noticed, that this behaviour (horizontal scroll bar reset) seems to be fixed with the following four small modifications:

Original:

reloadData(data, silent, columnsChanged){
return this.table.dataLoader.load(data, undefined, undefined, undefined, silent, columnsChanged);
}

Changed:

// Added replace argument
reloadData(data, silent, columnsChanged, replace = false) {
	return this.table.dataLoader.load(data, undefined, undefined, replace, silent, columnsChanged);
}

Original:

refreshSort(){
if(this.table.options.sortMode === "remote"){
this.reloadData(null, false, false);
}else{
this.refreshData(true);
}
//TODO - Persist left position of row manager
// left = this.scrollLeft;
// this.scrollHorizontal(left);
}

Changed

refreshSort(){
	if(this.table.options.sortMode === "remote"){
		this.reloadData(null, false, false, true);  // Added last argument
	}else{
		this.refreshData(true);
	}
	
	//TODO - Persist left position of row manager
	// left = this.scrollLeft;
	// this.scrollHorizontal(left);
}

Original:

refreshFilter(){
if(this.tableInitialized){
if(this.table.options.filterMode === "remote"){
this.reloadData(null, false, false);
}else{
this.refreshData(true);
}
}
//TODO - Persist left position of row manager
// left = this.scrollLeft;
// this.scrollHorizontal(left);
}

Changed:

refreshFilter(){
	if(this.tableInitialized){
		if(this.table.options.filterMode === "remote"){
			this.reloadData(null, false, false, true); // Added last argument
		}else{
			this.refreshData(true);
		}
	}

	//TODO - Persist left position of row manager
	// left = this.scrollLeft;
	// this.scrollHorizontal(left);
}

Original:

trigger(){
var left;
switch(this.mode){
case "local":
left = this.table.rowManager.scrollLeft;
this.refreshData();
this.table.rowManager.scrollHorizontal(left);
this.dispatchExternal("pageLoaded", this.getPage());
return Promise.resolve();
case "remote":
this.dataChanging = true;
return this.reloadData(null)
.finally(() => {
this.dataChanging = false;
});
case "progressive_load":
case "progressive_scroll":
return this.reloadData(null, true);
default:
console.warn("Pagination Error - no such pagination mode:", this.mode);
return Promise.reject();
}
}

Changed:

case "remote":
	this.dataChanging = true;
	return this.reloadData(null, undefined, undefined, true)  // Added the last three arguments
		.finally(() => {
			this.dataChanging = false;
		});

I do however not know if these changes would break something else.
@olifolkerd: If you think those changes would be ok, I would be happy to submit a PR 😊

@Anton-Plagemann Anton-Plagemann changed the title Horizontal Scroll Position Lost on Header Filter or Sort (only with Remote Pagination, Filter & Sort) Horizontal Scroll Position Lost on Header Filter, Header Sort or Pagination Changes (only with Remote Pagination, Filter & Sort) May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Possible Bug A possible bug that needs investigation
Projects
None yet
Development

No branches or pull requests

1 participant