How can we search multiple values in dt.column.search() function
How can we search multiple values in dt.column.search() function
dt.column(23).search('21').draw();
currently i am getting id of my categories in a column which is hidden. I can search for a particular value, in our case 21 would give me the output but what if i want to search more than one value at a time. lets say : dt.column(23).search('21|22').draw();
I tried this method any many differnt but no result. Hope anybody could help me with that
Currently, I have declared a button to filter one value which needs to be for two value.
table.button().add(
{
text: 'OSC',
action: function (e, dt, node, config) {
dt.column(23).search('14').draw();
},
},
});
This question has accepted answers - jump to:
Answers
dt.column(23).search('21|22', true, false).draw();
. Turn off the smart filter and turn on regex. Seesearch()
/column().search()
.Allan
Thank you that helped!
Another question, is it possible to get new data in datatable when a user adds a newentry on a different device but same table, without actually refreshing the page or ajax.
Currenlt, I am refreshing the ajax file which causes the table to get back on the top which is a problem to the users who might be working on the last entry of the page.
How are you doing this? I assume you are using
ajax.reload()
. You can stay on the same page by passing infalse
as the second parameter. See the second example in the docs. IF someone is interacting with the table this will likely still interfere but will stay on the same page.Another option is to use jQuery ajax() to fetch the updates and use
row.add()
orrows.add()
to add the new rows. Usedraw()
, passingfalse
as the parameter, to stay on the page but update sorting and searching. This will likely interfere with someone interacting with the table.You might need to use a global variable a a flag to decide whether to refresh the table or not. Set the flag
false
for example if the user is interacting with the table. When they are done then set the flag totrue
. If the flag istrue
then the table can be updated. Depending on how the user interacts with the table you may need to temporarily turn off the interaction will the ajax request is outstanding.Kevin
Alright thanks for letting me know will take a look at that.
For the first question, I created a regex function which does not seem to be working. I created a button when pressed filter a particular data from a column.I have defined it as follow:
And created a function to filter a value form the column
I have a datatable instace where I have defined a function passing custom value which is working fine: https://live.datatables.net/ucilib/80/edit
But the same concept doesn't work for me.
Am i missing any library or something.
The code above looks like it should do the trick. Could you update your example please so that it demonstrates the issue you want support with, it doesn't have any of the code (such as the button) that you're querying.
Colin
{
text: 'Launches',
action: function (e, dt, node, config) {
dt.columns().search('').draw();
var value = "74|75|76|77";
dt.column(24).search(value).draw();
AddToPageTitle("Filtered to Launch Entries");
},
},
well right now i am just using a pipe operator to filter multiple values from a column.
Serverside processing is also set to fasle. Weird, it was working fine the other day but now not working again.
That looks like it should work. If it isn't, we'd need a link to a page showing the issue.
Allan
As Allan explain ed earlier you need to enable regex searching and disable smart searching. See the
search()
docs for the different modes and thecolumn().search()
docs. You will want something like this:Kevin
Doh - I missed that the arguments weren't being passed in. Thanks Kevin!
Allan
Right now I have added a button to filter data from a column which is also working fine but the problem here is it only works with serverside set to true,but when false it does not work and I have a huge chunk of data of about 6k entries which is making it really slow. Is there an way where the regex still works when serverside is true or something similar
var table = $('#assyntCx_Table').DataTable({
]
});
THis is my custom button to filter entries
buttons: [
{
text: 'YCC Entries',
action: function (e, dt, node, config) {
dt.columns().search('').draw();
dt.column(26).search('3|1', true, false).draw();
AddToPageTitle("YCC Entries");
},]
Your description is confusing as I'm not sure if you mean that the regex search doesn't work with
serverSide: true
. I suspect that is the case as the server script would need to perform regex searching of the server data.I don't use any of the Datatables supplied server side processing scripts but my understanding is they don't support regex searching as it could have performance impacts with the queries. You will need to update the server side processing script you are using to perform regex queries.
Kevin
What I mean is "dt.column(26).search('3|1', true, false).draw();" I cannot use this when serverside is enabled but i can use "dt.collumn(26).search('1').draw(). when it is enabled so basically what i mean is how can i search multiple value with serverside enabled.
As I said the search is controlled by your server script. Are you using a Datatables supplied server side processing script? If so which one?
The script will need to be modified to perform regex or multi-value searches. How its done is dependent on the server script language and the data source being used. For example you might need to use REGEXP if using MySql.
Kevin
<?php
include_once("./utils.php");
$userID = check_session();
include("../lib/DataTables.php");
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;
$update = 'd M Y';
Editor::inst($db, 'ops_dailyLog OD', 'OD.id')
->field(
)
<?php > ?>->debug(true)
->process($_POST)
->json();
this is my server side script if that helps