How do I get semantic UI to work on my table
How do I get semantic UI to work on my table
DataTables makes it really convenient to display spreadsheets, and it looks great when other users are able to integrate Semantic UI with their tables as described here:
https://datatables.net/extensions/buttons/examples/styling/semanticui.html
I haven't been able to get it to work on mine though, I've loaded the semantic js and css files externally as you can see in this jsfiddle:
https://jsfiddle.net/ctd2xpfg/
Could someone point me in the right direction? With examples if possible. Thanks.
This question has an accepted answers - jump to answer
Answers
You setup the "External Resources" to use semanticui include files. But the HTML portion of the file is loading bootstrap files. This is probably resulting in conflicting CSS and JS file.
Kevin
I've removed the external resources and have now setup the HTML to load the semantic CSS and JS files. Where do I go from here?
You still have bootstrap CSS and DataTables' bootstrap integration CSS.
Probably conflicting, as Kevin already said.
You are still loading the bootstrap files.
Are you trying to use export buttons? If so you haven't loaded all the needed JS files nor configured Datatables to display them.
Kevin
Sorry I missed that, I've now removed the 2 files of Bootstrap (JS and CSS), and left the 2 files of DataTables Bootstrap Integration (JS and CSS) in the HTML.
I've also added the 2 files of Buttons (JS and CSS) in the HTML.
https://jsfiddle.net/hm123/ctd2xpfg/
Yes I want to use the Export Buttons, along with Semantic UI. How should I set the JavaScript configuration for that?
The example you referenced has an example:
https://datatables.net/extensions/buttons/examples/styling/semanticui.html
Each export button requires different JS files to be included. The example contains the list. You will need to add the buttons, the example shows you how.
Here is the Buttons docs:
https://datatables.net/extensions/buttons/
Kevin
I see. I've added each JS file required by each Export Button.
I can't seem to be able to get the code referenced in the example to work in my script. What am I missing?
https://jsfiddle.net/hm123/ctd2xpfg/
It doesn't look like you are loading
buttons.semanticui.min.js
. You are loadingdataTables.buttons.min.js
twice. Remove one of them.You have a function that gets the data then initializes the HTML Table then Datatables. This is the one you want to configure for the buttons. Add your
buttons: [ 'copy', 'excel', 'pdf', 'colvis' ]
andtable.buttons().container()
inside the function.Below that you have a configuration to initialize Datatables and add the buttons. You should remove this because its not going to work. First when this executes the table has not been inserted into HTMl by the function. Second is you can't initialize Datatables twice without some other coding to clear or destroy the first Datatable.
Kevin
It seems I mixed up the JS files, I've now corrected that.
Do I need to completely remove these 2 Bootstrap related CSS and JS files (Bootstrap DataTables Integration files) in order to get the Semantic UI working?
And will there be any conflict if I use both this regular Buttons CSS and this Semantic UI Buttons CSS together?
I've tried inserting the Buttons JavaScript, but obviously I'm doing it wrong because either I get no table, or I get the table but with errors and no buttons. How can I fix this?
https://jsfiddle.net/hm123/1tg7jjch/1/
If it weren't for the helpful community here at the DataTables forum I'd have given up on this by now.
Yup - I'd second that. This community is awesome. Thanks to people like Kevin for making it that way! .
What I would suggest to get Semantic UI working is to use the download builder - select "Bootstrap" as the styling option, and select the components you want. Then at the bottom, click the Individual files option. Copy the HTML from the bottom of the page and replace all instances of "bootstrap" with "semanticui". The download builder just hasn't been updated to include Semantic UI support yet (I'm kind of waiting on Bootstrap 4 to go beta, since I'll update it for that as well and want to just get it all done together).
Allan
Looks like you have a couple issues. You are still loading "dataTables.bootstrap.css". Run through the download builder as Allan suggested. Getting the correct files and putting them in the correct order is sometimes not easy.
Take a look at the browser's console and you will see a couple of errors:
This is due to not having a comma at the end of this line:
I think this is because you are loading
buttons.semanticui.min.js
before the base buttons code ofdataTables.buttons.min.js
. Reverse the order of these two lines.Kevin
I never expected the dev himself to answer my beginner question. I'd like to take this moment to say that DataTables is an awesome piece of software. Convenient and fully featured compared to the other table tools out there. Keep up the good work Allan.
And thanks a lot to Kevin as well, if it weren't for the fact he had stated himself he was just a user, I'd have thought him to be an admin or mod around here.
I've removed all instances of Bootstrap and replaced them with Semantic UI.
I tried inserting the UI styling, but nothing changes:
I've also added the comma and loaded the base Buttons JS before the Semantic UI Buttons JS. This makes the buttons show, thankfully, but only the 'copy' and 'columnvisibility' buttons seems to work, the 'excel' and 'pdf' buttons, when clicked, try to download, but end up 'failed due to an unknown error'.
https://jsfiddle.net/hm123/1tg7jjch/5/
I'm able to successfully download and open both Excel and PDF exports from your example. I tried with Chrome and Firefox on the Mac. What browsers have you tried with?
Kevin
I see. It seems this display error is specific to Android, yet it actually completes the download as they are in the downloads folder.
It seems the community is aware of this issue: https://datatables.net/forums/discussion/42607
I'm sure Allan will get it fixed whenever it's convenient.
Anyhow, what have I done wrong with my Semantic UI implementation?
I'm not familiar with how this UI should look or behave. What specifically is wrong?
Kevin
Semantic UI makes tables look amazing with its stackable layout:
https://semantic-ui.com/collections/table.html
It should be simple enough, just load the Semantic UI CSS and JS:
And apply that styling to the table here:
But nothing changes for me:
https://jsfiddle.net/hm123/1tg7jjch/5/
Everyone else seems to have been able to get it to work with DataTables in their examples:
https://datatables.net/extensions/buttons/examples/styling/semanticui.html
https://datatables.net/forums/discussion/30264/eta-on-semantic-ui-styling
https://datatables.net/forums/discussion/24163/feature-request-semantic-ui
Your lines loading the CSS are not syntactically correct. They should look like this:
Notice the end of each line looks like this:
rel="stylesheet" type="text/css" />
With a "/" at the closing ">".
I think you can remove the 4th CSS for "dataTables.min.css".
That should provide the display you are expecting.
Kevin
I missed the CSS syntaxing, corrected that now.
I've also removed this 4th Button CSS:
I've applied the Semantic UI styling on the table:
And it works beautifully. Thanks Kevin.
https://jsfiddle.net/hm123/utyp73yu/10/
If I wanted to align individual columns in different ways(left, right, center), what would be the best way to do that?
Also, how do I get the Paging CSS (Show 'X' entries) to show up in Semantic UI as in this example:
http://jsfiddle.net/kmd1970/37enwegd/
And is it possible to export as an image (PNG or JPEG, with just the copied text saved as a graphic with a plain background)?
He does deserve a promotion, no question - but I'm not sure mod/admin is a promotion...! ;-)
Apply one of the Semantic UI classes for text alignment using
columns.className
.Are you loading the Semantic UI Javascript?
Darn good question. Currently no - that isn't something that DataTables provides, but if we can get an image from the HTML table, it would be relatively easy to do (its that getting the image part that I'm not sure about).
Allan
I've tried your suggestion with the columns, but maybe I'm doing it wrong, as nothing changes:
I notice this sets my footer and column headings below the table (which was previously set on top)
Is there a way to align individual columns with CSS?
My jsfiddle:
https://jsfiddle.net/hm123/utyp73yu/14/
Yes I'm loading the Semantic UI JS:
I was wondering, does the PagingType option affect table render speeds?
Should be:
No.
Allan
Changed the CSS, but still no luck with the individual column alignment.
https://jsfiddle.net/hm123/utyp73yu/16/
What could I be doing wrong to have the Paging button (Show 'X' entries) to show up in regular DataTables CSS instead of Semantic UI CSS?
I was also wondering if it is possible to output as doc (word, Google docs readable) the way we output to excel or PDF?
As for copy,
I inserted the following code to change the output, but my edits don't show in the clipboard:
How do I add a blank line break between every cell text in the output? Which of these in which configuration do I use: fieldSeparator, fieldBoundary, newline
Is it possible to output to the clipboard in the following format:
Example:
As opposed to the current squashed up format:
Example:
Try this:
I removed this to change the style of the info text. You will need to do the same in your code:
There is not a Datatables Extension for this. Not sure if there are other tools that can export a table into Word format.
You can use the
customize
function within the copy button to modify the output. This isn't exactly what you want but its a start:It outputs the raw string so you can see the raw string in the console. Then uses a couple of regex replacements to modify the string. The first replaces each
\n
with two for a line break between each row. Then it replaces\t
with\n
for a line break between each column. I don't want to take all the fun from you so I'll let you update the regex's to add the "Claims:" and "Total Awarded:". If you have troubles with this post back. Regex is not always easy if you aren't familiar with it. Finally it returns the updated data.Kevin
That column alignment worked perfectly.
As for changing the PagingButton CSS (show 'X' entries'), I tried your instruction:
But the PagingButton still looks like the default, is there some further step needed to make it show up in Semantic UI CSS?
Also, What would be the best way to get the content of two cells of two different columns to show up side by side? Kind of like a merge, or span. Meaning instead of this:
To show up like this (first 2 columns, header and data, side by side):
I'll see if I can work out this regex, it'll take some time (and a lot of trial and error). I'll post back if I get stuck. Thanks Kevin.
I didn't save the change of removing that CSS from your page. Did you try removing it?
You will also notice that the font of the table data changes too.
One option is to remove the column for H2 and render the data for H1 and H2 into one column using
columns.render
. However if you want two columns then maybe you need to use CSS to apply the cell borders. Looks like Semantic UI usescelled
to apply cell borders. You can simply remove that then align H1 right and H2 left. I'm not well versed in CSS so won't be much help.Kevin
I notice the font changes yes, but not the styling of PagingButton
Here's a saved jsfiddle with the body removed:
https://jsfiddle.net/hm123/256ogfje/2/
https://i.imgur.com/E0lqn6F_d.jpg?maxwidth=640&shape=thumb&fidelity=high
Here's how I want it to look:
http://jsfiddle.net/kmd1970/37enwegd/
https://i.imgur.com/S2x1Wpb_d.jpg?maxwidth=640&shape=thumb&fidelity=high
Sorry, I thought you were referring to the paging info and buttons at the bottom of the table. The first image shows a square page length button. Is that the change you are looking for?
The page length option looks the same to me in both fiddles. I'm not really sure what you want and even if I was I probably wouldn't be much help. However this thread has some information on changing the Semantic UI layout. Not sure if anything has changed since but you can apply the defaults by adding the below into your Datatables initialization.
You can use the
dom
to update the controls.Kevin
Regarding regex, is it possible to configure a regex search in just one individual column?
Yes -
columns().search()
.Allan