How do I search on a datetime column
How do I search on a datetime column
obrienj
Posts: 93Questions: 38Answers: 0
Allan,
Assuming the following works for text fields (and it does except for the column "Start"):
The search modal table definition:
.
.
<tr id="filter_col14" data-column="start">
<td>Start</td>
<td align="center"><input class="column_filter" id="col_start_filter" type="text"></td>
</tr>
<tr id="filter_col0" data-column="title">
<td>Title</td>
<td align="center"><input class="column_filter" id="col_title_filter" type="text"></td>
</tr>
<tr id="filter_col1" data-column="description">
<td>Description</td>
<td align="center"><input class="column_filter" id="col_description_filter" type="text"></td>
</tr>
.
.
The processing code:
//---------------------------------------------------------------------------------------
// Handle keystrokes from the individual column filter inputs
//---------------------------------------------------------------------------------------
$('input.column_filter').on('keyup click', function () {
filterColumn($(this).parents('tr').attr('data-column'));
});
//--------------------------------------------------------------------------------------
// Execute the column filters
//--------------------------------------------------------------------------------------
function filterColumn(name) {
$('#cc-list').DataTable().column(name + ':name').search(
$('#col_' + name + '_filter').val(), false, true).draw();
}
The column "Start" is the column "start" in the table defined as "datetime".
I would like the user to enter "August 14, 2017 1:30 PM" character by character as with text fields and look up those rows on the server-side like all the rest.
How would I do this?
Regards,
Jim
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
This is with server-side processing? You'd need something at the server-side that will translate the date from the human readable string to ISO8601 (i.e.
yyyy-mm-dd
).Your problem there might be, what to do with "Augu" as someone is typing it in. It might be that you want to use a date picker to let them select the date immediately.
That doesn't negate the fact that something needs to translate it into a format that whatever server-side processing script you are using will still need to translate it though.
Allan
Allan,
Your response was as I expected but was hoping I missed something.
But I have the luxury of adding a column with the formatted date in text solely to be searched as date searching is a major requirement.
Thanks for the input.
Regards,
Jim