Horizontal scroll bar is not shown when datatable is empty
See original GitHub issueI’m submitting a … (check one with “x”)
[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, post on Stackoverflow or Gitter
Current behavior
If I am using [scrollbarH]=“true” and if there it is no rows in datatable, the horizontal scroll bar is not shown, and header is cut off and cannot see more header columns in right side.
Expected behavior
Horizontal scroll bar shows on page and user should be able to see header columns even datatable is empty.
Reproduction of the problem
in demo HorzVertScrolling, comment out this code snippet: /* this.fetch((data) => { this.rows = data; }); */
you can find there is no horizontal scrolling bar and state column on right side is hidden.
What is the motivation / use case for changing the behavior?
This is not a user friendly experience when the table is empty.
Please tell us about your environment:
- Table version: 0.8.x
swimlane/ngx-datatable: “11.2.0”,
- Angular version: 2.0.x
angular/common: “^4.1.3”
- Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
Chrome
- Language: [all | TypeScript X.X | ES6/7 | ES5] typescript: “2.5.3”,
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:11
Top GitHub Comments
I had same issue, but doing lots of R&D , I did some custom code, it solve my problem. I created a common method and call from component when data not available.
like : setEmptyMessage() { let msg = ‘No data to display.’; if (!this.tableData.length) { this.tableData = [{ ‘message’: msg }]; } else { delete this.tableData[0][‘message’]; msg = ‘’; } this.setEmptyMessageDataTable(msg); }
// create a common method like this setEmptyMessageDataTable(msg) { const hideClass = document.querySelector(‘datatable-body-row’); const divelm = document.querySelector(‘#noMsg’); if (msg) { if (hideClass) { hideClass.setAttribute(‘style’, ‘display:none;’); }
// use setEmptyMessage() where you are fetching dataTable data
this.yourApi.method(req).subscribe( results => { this.setEmptyMessage(); }, error => { } )
A more improved version of the fix, instead of using scrollLeft, use the transformers that the data table uses internally, I made this improvement because we found some inconsistencies when the table has one row, the user scroll to the right and finally add another filter to remove the row, in that scenario the header scroll messed up.