Date Search
Date Search
Hi Everyone,
I would like to know if there is a way we can search rendered dates, here is my code with Date column Hire Date.
'columns': [
{ data: 'emp_no' },
{ data: 'first_name' },
{ data: 'last_name' },
{ data: 'gender' },
{ data: 'hire_date',
"render": function (data) {
var dateObj = new Date(data);
var month = ('0' + (dateObj.getMonth() + 1)).slice(-2);
var date = ('0' + dateObj.getDate()).slice(-2);
var year = dateObj.getFullYear();
//var shortDate = year + '/' + month + '/' + date;
return (date + '/' + month + '/' + year);
}
Any suggestion is highly appreciated.
This question has an accepted answers - jump to answer
Answers
Hi @SalmanS ,
It should search those, since it's being returned for all rendering types (display, filter, etc). We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Apologies, here is the fiddle please.
http://live.datatables.net/gocuzusa/7/edit
Your example was generating this error:
VM46 jquery.dataTables.js:3104 Uncaught TypeError: Cannot set property '_DT_CellIndex' of undefined
You added an
Action
column but only populated two rows with the column. The error was generated because the column was missing in the other rows. I removed those rows. Searching for the date that you render seems to work:http://live.datatables.net/zamiyona/1/edit
Kevin
Hi Kevin,
Many thanks for the update, the on.click is not alerting the name from first column?
If you have a moment, please see the same fiddle, do you see any errors?
or am I missing something?
You are getting this error:
Uncaught ReferenceError: e is not defined
You can look at the browser's console for these errors.
You need to pass the
e
parameter in your event handler functions:http://live.datatables.net/zamiyona/2/edit
Kevin
Thanks kevin,
I tried the following and it doesnt work
http://live.datatables.net/zamiyona/6/edit
You code is working. If you look at the console you will see this message:
Ignored call to 'alert()'. The document is sandboxed, and the 'allow-modals' keyword is not set.
Alerts don't work when in edit mode in JS BIN. You have two choices:
output
tab click the arrow that is pointing up and to the right. This will open the page in a new tab allowing the alerts to work.Kevin