How to use Datatables jQuery UI datetime picker outside of the table.
How to use Datatables jQuery UI datetime picker outside of the table.

Good Afternoon Allen, Everyone,
First, I just want to say I absolutely LOVE DataTables. The software is superb and the documentation, examples, community and forums are second to none! I have finally run into an issue that I can't figure out with your samples and docs, however.
I am building a CRM for our office using DataTables as it's backbone. This is on a LAMP server with MySQL.
My issue is this. I want to use the same date/time picker that is used by DataTables in the Entry Date column bubble edit (scroll all the way to the right) outside of the table. And click on any cell in the Entry Date column.
Specifically, I want to be able to use that same picker to populate the Date, Start Date, and End Date fields you will see if you Click the "Filter Button" at the top, but instead I just get the standard jQuery UI datepicker.
I'm adding these to the text inputs with the following in the Table instantiation:
"fnInitComplete": function(oSettings, json) {
// Add datepickers to the date filter fields.
$( "#quick_filter_date" ).datepicker({
dateFormat: "mm-dd-yy"
});
$( "#quick_filter_start_date" ).datepicker({
dateFormat: "mm-dd-yy"
});
$( "#quick_filter_end_date" ).datepicker({
dateFormat: "mm-dd-yy"
});
}
Is there a way to call the same pickers used in the bubble edit for the Entry Date field, but used outside of the table? I'd like my datepickers to match.
Now, I could just go get the datetime plugin separately, and then style it the same, but I feel like I'd be loading the jQuery UI datepicker plugin twice if I do it that way.
I'm sure this is something obvious I'm just missing, but changing .datepicker above to .datetimepicker throws an error and I'm reasonably sure calling these in the fnInitComplete function should ensure they are called after the Datatables bundled itself is called. (In addition to this code being called in the foot when the Datatables stack is all called in the head)
Thank you for your time!
This question has accepted answers - jump to:
Answers
Editor can be used without a DataTable. You could possibly use the Editor standalone functionality to implement the filter portion of your page. That way it should give you access to the datetime field type.
See here - https://editor.datatables.net/manual/standalone
Hi,
Thanks for your kind words - great to hear that you are enjoying using DataTables so far!
I'm afraid that there is currently no option to use the date picker from Editor outside of Editor itself, as it is built into the Editor software and not exposed via an API. You aren't the first to ask about this, and it is something that I would like to do in future as it can be useful (indeed, I have plans in that direction for additional plug-ins
).
@rduncecb's suggestion of using a standalone Editor is a clever one, I hadn't thought of that myself! That might work well - you could use another Editor instance with your three external date time fields and activate editing on them when clicking on them. You might need to style them a little to make them look clickable.
Another option is to use Pikaday which is similar in styling to the one built into Editor (it was the inspiration for some of the styling - I love the plain and simple look).
Allan
Thanks to rduncecb and allan for your help! I have now implemented a purely client side solution based on rduncecb's answer. Note, this example is based on NO backend datasource and forces the editor closed (and returns false) from the preSubmit method of the inline usage. In this way however, I am able to essentially use the Datatables datetime picker to populate fields outside of the main table.
HTML - Pretty standard. Mostly borrowed from the standalone inline editor example.
JS - I have no need to write any of these values to any data source, whether that be front end, AJAX, JSON or otherwise, they will only be used for the purpose of client side filtering. This codes only purpose is to be able to use the Datatables Editor datetime picker to populate a field on the client side.
So there you have it, this example could probably be improved upon, but this should get anybody with a similar question started using the Datatables built in datetime picker from a separate standalone instance of Editor. Thank you again for the suggestion.
Awesome. Thanks for posting back with your solution!
Regards,
Allan
Glad I could help
In reference to your comment about getting the field from the editor, you should be able to use one of the options below to stay within the Editor API:
API - https://editor.datatables.net/reference/api/get()
or
API - https://editor.datatables.net/reference/api/field().get()