searchBuilder with Bootstrap 5, how can i initialise all buttons with class btn-primary?
searchBuilder with Bootstrap 5, how can i initialise all buttons with class btn-primary?
sovap
Posts: 4Questions: 3Answers: 0
Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
By default the buttons from searchBuidler extension are initiliased with class "btn-secondary"
Is there any way how to initialise them with a different class?
I know I can change it afterwards with jquery but that is not an easy solution as a lot of buttons are added to the page later on when the searchBuilder is used...
This question has an accepted answers - jump to answer
Answers
I forgot whether the following works or not to overwrite it or just append a new class to the original classes:
But a more directly way is:
https://github.com/DataTables/Buttons/blob/0c81c91fe4202a954d57fe1b54cc0fe066056c17/js/buttons.bootstrap5.js#L11
Since I make too many customizations, it would be better for me to remove unwanted classes directly.
I have tried the following without success.
1) added buttons to the init:
2) Added your code from repo to custom js file where i changed the classes and then added the file to html.
Unfortunately its not working for me as you can see in the picture:
You put the code in the wrong place I'm afraid.
It should be put inside the layout.
See: https://live.datatables.net/bohikofo/4/edit?html,js,output
It replaces the default classes with different classes.
Since you haven't provided a reproducible example, I have no idea how you want the search builder to be created, and what css files you're using.
(Please do so in the future, as it is difficult to help based only on description.)
So I only make the example to simply show how to overwrite the classes of the Button that will open the search builder using button initialization way (https://datatables.net/extensions/searchbuilder/examples/initialisation/buttonOptions.html).
Note the CSS conflict:
<link href="https://cdn.datatables.net/buttons/3.2.0/css/buttons.dataTables.css" rel="stylesheet" type="text/css" />
This style and Bootstrap 5 button styles will conflict. Since the search builder window has classes "dt-button-collection dtb-collection-closeable" that is defined in
buttons.dataTables.css
, you can use the file and remove unwanteddt-button
ordt-buttons
styling that affects thebtn-primary
overwrite before.I also didn't see Example on https://datatables.net/extensions/searchbuilder/examples/ shows how to use button initialization and with Bootstrap 5, but yeah, there will be a CSS conflict.
If you want to change the Search Builder Bootstrap button styles "within" the search builder window, check: https://github.com/DataTables/SearchBuilder/blob/master/src/searchBuilder.bootstrap5.ts
(if you use the cdn, then it is the file: https://cdn.datatables.net/searchbuilder/1.8.1/js/searchBuilder.bootstrap5.js)
and directly replace
btn-secondary
with the class you want.Or as I show in the example, use:
DataTable.SearchBuilder.classes.clearAll = 'btn btn-primary dtsb-clearAl';
to change the classes inside the window