An internal function to filter (search) by type === 'sort'
An internal function to filter (search) by type === 'sort'

I have a birthday_column in my Datatable. The raw data are like "2022-05-19", but users see and filter data like "May 19, 2022":
{ targets: [number_of_birthday_column],
"data": "date_of_birthday",
"render": function ( data, type, row, meta ) {
if (type === 'sort')
{
return data; // 2022-05-19
}
else
{
return dateToText(data); // May 19, 2022
}
}
}
I need an internal DataTable function to filter (search) by raw data ("2022-05-19"), but the rest must work the same as now (displaying "May 19, 2022" and filtering by "May 19, 2022" for users should remain without change).
Is it possible? Is there a working code example to see?
This question has an accepted answers - jump to answer
Answers
What's the input for your "internal" search? You could use a custom function, in which case you are in control of the data and format and the end user can filter as a string on the rendered data.
Allan
The input for "internal" search is like 2022-05-19. I don't know how to perform such searches because 'filter' type contains data like May 19, 2022 and I don't want to change this.
One option is to use
search.fixed()
orcolumn().search.fixed()
with a function to compare the "internal" search term to the original data using a function. See this example with your column definition.https://live.datatables.net/yefusayo/1/edit
It uses a different raw date format of
2011/04/25
. To try it typeoct
in the global search input to see all the dates withOct
. Next type2009/10/09
in the Internal search input to see the table futher filtered to show one record.The key code is this:
It compares the
Internal Search
input value, ieinternalSearch
, to the raw date data in each row.Kevin
Yup - what Kevin says