How to add checkboxes to items in The Buttons: Colvis drop down menu?
How to add checkboxes to items in The Buttons: Colvis drop down menu?
Walter_Stolz
Posts: 46Questions: 6Answers: 0
Previously, I used Colvis plugin to manage column visibility.
Now I tried to use The Buttons extension: Colvis, but there is no checkboxes in this version of plugin.
How to add checkboxes to items in The Buttons: Colvis drop down menu?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You mean this?
There is no checkboxes in drop down menu in your example.
Was verify thats what you meant by the menu
Unless you get auper down and dirty with jquery in the dom, like replacing content with checkboxes, i dont think you can.
Makebyour own, using the api
I don't want to replace content with checkboxes, I just want to add checkboxes to items in dropdown menu, to make view like in old colvis plugin.
http://postimg.org/image/50wutub13/
Oh I see. Well I don't think theres a way to do it via any DT settings. Sorry
To jLinux: Thanks.
OK, Maybe someone else knows how to add checkboxes any way.
Does it have to be in the dropdown menu? I mean you can definitely accomplish this with your version
I am trying to recreate my old tables with new DataTables 1.10.10, so the dropdown menu must be the same (see picture), with checkboxes.
There is the similar solution with checkboxes for Select plugin:
https://datatables.net/extensions/select/examples/initialisation/checkbox.html
I tried many combinations to use this for The Buttons extension:Colvis plugin.
For example:
1) I tried to replace selector with:
a.buttons-columnVisibility:nth-child(1)
or
a.dt-button.ui-button.ui-state-default.ui-button-text-only.buttons-columnVisibility
2) I tried to add 'select-checkbox' class to Colvis button options:
buttons: [{extend: 'colvis', columnDefs: [ {className: 'select-checkbox',targets: 0}}]
3) Tried to replace in CSS:
table.dataTable td.select-checkbox
to
table.dataTable div.dt-button-collection.dt-button.select-checkbox
or
table.dataTable a.dt-button.ui-button.ui-state-default.ui-button-text-only.buttons-columnVisibility.select-checkbox
But it didn't help.
Mind if i ask qhy its so important to have check boxes? The buttons do the same thing.. they toggle the biaibiliyy just like the checkboxen
I am just trying to recreate the new tables design similar to the old one.
It's almost complete, and I use jQueryUI styles for tables, which also consist different colors(checked|unchecked and hovered) for the Colvis menu items.
For me, it's not so important: in my old versions of tables were checkboxes, in new will be jQueryUI colors for selection. But how users will understand this?
Reposting from our PM conversation about this:
If you want to use
<input type="checkbox">
in the Buttons column visibility you would probably need to modify the button text generation. You'll also need to add event handlers for the checkbox itself.The CSS approach will likely be much easier to actually implement.
Checkbox support is not something I plan to add to the column visibility buttons.
Allan
I suspect that the CSS approach will be easier, but I can't find the name of class, to which it is necessary to change td.
table.dataTable td.select-checkbox
I tried to replace
to
table.dataTable div.dt-button-collection.dt-button.select-checkbox
table.dataTable a.buttons-columnVisibility:nth-child(1).select-checkbox
table.dataTable a.dt-button.ui-button.ui-state-default.ui-button-text-only.buttons-columnVisibility.select-checkbox
But checkbox didn't appear.I know how to create checkbox (I mean css style parameters), but I don't know on which place it should be (class name).
a.dt-button.buttons-columnVisibility
for the base button and addactive
for the active state (this is for the DataTables default styling).That bit is going to be wrong. The button is not inside the HTML table.
Allan
Thanks for the way to solution.
I found the solution only with CSS without any javascript.
a.dt-button.buttons-columnVisibility.ui-state-active:before - must be used for Checked button.
a.dt-button.buttons-columnVisibility:before - for unchecked.
Hi Walter,
I have this requirement too. Can you elaborate a little how to apply this CSS in for column visibility?
I have a similar question: Is there a way to get the column visibility item buttons to use the HTML in the column headers if they have it? Currently, the HTML appears to be stripped, so the button items do not match the column headers.
Currently no - not without modifying the Buttons code (which of course you are welcome to do).
I plan to resolve this properly with the next major update to DataTables - although that is likely some time away.
Allan
Here is my few strings (which helps you to add the checkboxes) from global.css:
checkbox.png link: http://s10.postimg.org/ma95a7fs5/checkbox.png
Haven't looked into this too deeply. This could be used somehow on button init:
It currently only works running when the dropdown is visible. I would have to find when it could be triggered (or how to access the dropdown when the colvis button has not yet been clicked).
+1 for the checkbox idea
+1. Would be great this feature built-in.
Below CSS worked for me.
/CSS to add checkboxes to colvis items/
.dt-button-collection a.buttons-columnVisibility:before,
.dt-button-collection a.buttons-columnVisibility.active span:before {
display:block;
position:absolute;
top:1.2em;
left:0;
width:12px;
height:12px;
box-sizing:border-box;
}
.dt-button-collection a.buttons-columnVisibility:before {
content:' ';
margin-top:-6px;
margin-left:5px;
border:1px solid black;
border-radius:0px;
}
.dt-button-collection a.buttons-columnVisibility.active span:before {
content:'\2714';
margin-top:-11px;
margin-left:8px;
text-align:center;
text-shadow:1px 1px #DDD, -1px -1px #DDD, 1px -1px #DDD, -1px 1px #DDD;
}
.dt-button-collection a.buttons-columnVisibility span {
margin-left:8px;
}
Nice one - thanks for sharing that with us!
Allan
I would like have the same functionally with latest code. it seems not working with current version