simple-datatables icon indicating copy to clipboard operation
simple-datatables copied to clipboard

Responsive Mobile

Open flexsoluciones opened this issue 1 year ago • 1 comments

Responsive datatable on mobile like

https://www.tailwindtoolbox.com/components/responsive-table thanks

flexsoluciones avatar Mar 23 '24 18:03 flexsoluciones

new DataTable('#example', { responsive: true, rowReorder: { selector: 'td:nth-child(2)' } });

flexsoluciones avatar Apr 03 '24 19:04 flexsoluciones

This can be done easily with CSS. Example: https://pccd.dites.cat/fonts (code):

table td,
table th {
    display: none;
}

/* Show only the title column on the smallest devices */
table td:nth-child(3),
table th:nth-child(3) {
    display: table-cell;
}

/* For screens that are a bit bigger, show the author column too */
@media (min-width: 400px) {
    table td:nth-child(1),
    table th:nth-child(1) {
        display: table-cell;
    }
}

/* For larger screens, show all columns */
@media (min-width: 640px) {
    table td,
    table th {
        display: table-cell;
    }
}

pereorga avatar Aug 21 '24 15:08 pereorga

@pereorga So should this be added to the CSS in the library somehow? As a separate stylesheet or alike? Or is this something you think individual projects should use themselves? @flexsoluciones Is that what you were looking for?

johanneswilm avatar Aug 21 '24 15:08 johanneswilm

I'm not sure if this should be added to the library, I would say it can be implemented by the projects themselves.

Maybe it could be added as an example, as part of the documentation.

pereorga avatar Aug 21 '24 16:08 pereorga

FWIW, my code example works with JS disabled too (Simple DataTables is obviously not initialized, but the HTML table is rendered responsive without the need of JS). I imagine that wouldn't work if the responsiveness is provided by the library.

pereorga avatar Aug 21 '24 16:08 pereorga

Maybe it could be added as an example, as part of the documentation.

Yes, I think maybe we should add a demo that includes this CSS as an example.

Btw - @pereorga if you specify either the scrollY or the fixedWidths option, it will render the table in the dom and take measurements on each column to see the size of everything. It does that whenever update() is being called (given certain settings). If you haven't done that yet, I think we need to test whether hiding columns with CSS will influence that. Measurements are automatically retaken when resizing the browser window, so that part should be covered.,

johanneswilm avatar Aug 21 '24 16:08 johanneswilm

Btw - @pereorga if you specify either the scrollY or the fixedWidths option, it will render the table in the dom and take measurements on each column to see the size of everything. It does that whenever update() is being called (given certain settings). If you haven't done that yet, I think we need to test whether hiding columns with CSS will influence that. Measurements are automatically retaken when resizing the browser window, so that part should be covered.,

I could not find fixedWidths in the documentation. I found fixedColumns, which I tested locally and at least in my example it does nothing (so it works well with this CSS, but I fail to understand what this is supposed to do)

I tried scrollY, and it worked well with these CSS rules, but for some reason it duplicated the filters I have in the headings (but this behavior seems to be unrelated to this CSS example)

pereorga avatar Aug 21 '24 16:08 pereorga

@pereorga Thanks for the contribution and the testing. I have now added a demo with this.

johanneswilm avatar Aug 21 '24 17:08 johanneswilm

but since most people using mobiles than PCs these days, responsiveness should be default...not optional imo.

we should add that somewhere inside the project css or if people use bootstrap framework, atleast its responsiveness should be utilized.

thanks,

lorvent avatar Sep 06 '24 17:09 lorvent

@lorvent Datatables are used in many scientific and business production systems where mobile phones are rather irrelevant. I think we better not push a specific ideology on all users.

johanneswilm avatar Sep 06 '24 17:09 johanneswilm

ok...i get your point (eventhough i don't agree with it as i don't have knowledge of what you are saying, thats my fault, not yours)

how about a seperate style sheet? those who need it, can add.

lorvent avatar Sep 06 '24 19:09 lorvent