How to add scroll-y to one cell in a row?
How to add scroll-y to one cell in a row?
My test case is at https://jsfiddle.net/pmi2018/8ryhtacp/
Description of problem:
As the browser window shrinks/grows in size, the "Notes" column makes each row height grows/shrinks. I would like to add a vertical scrollbar to the "Notes" column so the row height does not change with different browser window sizes (e.g from cell phone screen to large desktop screen), and the user can scroll through the note for that row without affecting the other notes or row sizes. I would like to limit the the row size to roughly 2 lines of text so the user see there is more text in the "Notes" column and can read the start of the note.
I am also open to suggestions of other ways to keep the table rows to one or two lines and still allow the user to read part of the note and then have a mechanism to read the entire note. There are normally links in the notes, but I took them out to make the test case easier to use.
Thanks!
This question has accepted answers - jump to:
Answers
You are 90% of the way there! Use a
max-height
on thediv
to force it to a smaller height and let the scrolling kick in.Updated example: https://jsfiddle.net/67uraLk5/ (I used a class rather than an inline style).
Allan
You could do something like this Stack Overflow thread suggests. Use
columns.classname
to assign a class to thetd
and create a CSS to set the desired height. Then usecolumns.render
to place the cell data in adiv
that hasoverflow: auto
set.It might be easier to use the ellipsis plugin.
Kevin
@allan Unfortunately, your fiddle does not load for me. All i get is the bouncing cloud. Can you check the url? I would love to see what you did!
I think there were issues with jsfiddle as I couldn't open it either. But now I can. Try again. In case you can't open it he did this:
Kevin
@kthorngren Thanks for the ellipsis plugin idea. It sounds much better than my vertical scrolling idea.
I seem to be having an issue getting it to work. I forked my original fiddle to try it out.
https://jsfiddle.net/pmi2018/x2nktpus/
@kthorngren Thanks. I can now see what @allan did.
It is what I originally envisioned. I still like the ellipses idea. Can you see what I missed in my attempt at implementing it?
@allan Just what I envisioned! One small nit. When I shrink the browser window, the whole table has to be scrolled to the right to make the vertical scrollbars visible. Is there a way to not have the horizontal scrolling?
The fiddle doesn't have any Javascript code to init Datatables nor does it load the ellipsis plugin. Possibly you didn't save the changes. I updated the example here with a couple more Datatables CSS includes to support BS5:
https://jsfiddle.net/4r8y3boe/2/
I removed the
div
in the cell data.The version of Datatables you have in the test case doesn't support the
DataTable
API so you will see this error:This was added to a later version of Datatables. Either upgrade your Datatables or use the old syntax:
Kevin
@kthorngren You are correct, I did not save the fiddle after I made the changes. https://jsfiddle.net/pmi2018/x2nktpus/2/
Thanks for the tip on updating the DataTables package. The site is old, so I probably need to update a few other packages.
Thanks so much!!!