How to make a responsive datatable? #2652
Replies: 1 comment 8 replies
-
I definitely see what you want to do but this is a tricky one as you need to detect the reflow and then act on it with some you can MonkeyPatch the datatable reflow method to basically inject your code to handle your styles. here is a MonkeyPatch you can tweak on your own. if (PrimeFaces.widget.DataTable) {
PrimeFaces.widget.DataTable.prototype.initReflow = function() {
var headerColumns = this.thead.find('> tr > th');
for (var i = 0; i < headerColumns.length; i++) {
var headerColumn = headerColumns.eq(i),
reflowHeaderText = headerColumn.find('.ui-reflow-headertext:first').text(),
colTitleEl = headerColumn.children('.ui-column-title'),
title = (reflowHeaderText && reflowHeaderText.length) ? reflowHeaderText : colTitleEl.text();
var column = this.tbody.find('> tr:not(.ui-datatable-empty-message,.ui-datatable-summaryrow) > td:nth-child(' + (i + 1) + ')')
column.find(".ui-column-title").remove(); // #11078
column.prepend('<span class="ui-column-title">' + PrimeFaces.escapeHTML(title) + '</span>');
}
}
}; |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I am trying to make a datatable, where each column has if specific width and it looks perfect, like this:
(Please don't pay attention to the logo).
I have reflow = true, for the responsive view, but when viewing the page on a mobile device, the table looks like this:
(Please don't pay attention to the logo).
My idea is that when switching to responsive view, the width of each column goes to “auto” and the text alignment to “left”. I tried with some “Media Query”, but nothing works. I searched in the showcase, but all the examples, in any case, do not specify width and alignment for each column, so by default they are already set to “auto” and “left”.
This is the code of the page.
I appreciate any help.
Beta Was this translation helpful? Give feedback.
All reactions