am trying to apply filter on the remote datatable with KTDatatable.
It is metronic 9.x
I do not see any documentation where I could pass all filter criteria with the apiEndpoint URL. or even a textbox search /.... infact i cant even get the search text box to show up even if i put search:true or search:"a"
I have referred the documentation located at https://keenthemes.com/metronic/tailwind/docs/components/datatable
using it with codeignitor 4
Hi BizDev Apurva
Sorry for the delay. The KTDataTable component does not automatically generate search input boxes. You need to create these elements yourself in your HTML and connect them to the datatable using data attributes.
Add this HTML before your datatable element:
<!-- Search input for datatable -->
<div class="mb-5">
<input
type="text"
class="form-control"
placeholder="Search..."
data-datatable-search="#kt_remote_table"
/>
</div>
<!-- Your datatable -->
<div ></div>
// Connect search input to datatable
document.querySelectorAll("[data-datatable-search]").forEach((searchElement) => {
const tableId = searchElement.getAttribute("data-datatable-search");
const datatable = document.querySelector(tableId);
if (datatable && datatable.instance) {
searchElement.addEventListener("keyup", () => {
datatable.instance.search(searchElement.value);
});
}
});
const dataTableOptions = {
apiEndpoint: apiUrl,
// ... other options
search: {
delay: 500, // Milliseconds to wait before searching after typing stops
// Optional custom search callback for client-side filtering
callback: function(data, search) {
// This is only used for client-side filtering
// For remote, the search term is sent to the server
}
},
// Other options...
};
const dataTableOptions = {
apiEndpoint: apiUrl,
// ... other options
mapRequest: (queryParams) => {
// For CodeIgniter 4, you might need to adjust how parameters are sent
queryParams.set("ci_search", queryParams.get("search")); // Rename search parameter
// Add CSRF token if needed
queryParams.set("csrf_token_name", document.querySelector("meta[name="csrf-token"]").content);
return queryParams;
},
// Other options...
};