Posting Additional Fields To The Server
Posting Additional Fields To The Server
I have added two date pickers, which I intend to use for selecting a start date and end date, to establish a date range search of one date column in the table. My table uses server side processing.
I think I've got everything else done, but can't figure out how to add those two fields when they are selected, to the regular post to the server. To be clear, the date range selection will happen first, followed by any additional searching on columns. The selection of two date ranges should trigger a post to the server end point, with those two fields included. After which, a second post can provide the rest of the fields for regular column searching.
Alternatively, we can wait and send all the fields in one post, if that is easier to implement.
This is the script I'm using for the two date fields:
$("#startDate").datepicker({
uiLibrary: "bootstrap4",
iconsLibrary: "fontawesome",
select: function () {
// This is the onselect event. Not sure what goes here to trigger the table search.
// I can get the current date values from the html input tags.
},
header: false,
showRightIcon: false,
format: "m/dd/yyyy",
maxDate: function () {
return $('#endDate').val();
}
});
$("#endDate").datepicker({
uiLibrary: "bootstrap4",
iconsLibrary: "fontawesome",
select: function () {
// This is the onselect event. Not sure what goes here to trigger the table search.
// I can get the current date values from the html input tags.
},
header: false,
showRightIcon: false,
format: "m/dd/yyyy",
maxDate: new Date(),
minDate: function () {
return $("#startDate").val();
}
});
My datatable server script:
var t = $("#table").DataTable({
processing: false,
serverSide: true,
ajax: {
url: "/Reports/Data",
type: "post",
},
Answers
Use
ajax.data
to post extra data to the server (example) and then useajax.reload()
to trigger a reload of the Ajax data.Allan