Introducing ReUI:Open-source UI components and apps built with React, Next.js and Tailwind CSS
Browse ReUI

How to Pass Custom Parameters to Server-Side KTDataTable Requests


Hi everyone,

I'm using the Metronic theme (bootsrap) with KTDataTable in a .NET 8 Core project. I have successfully implemented server-side pagination, but I'm having trouble passing custom parameters (e.g., idCompany and idWallet) to the backend.

I've tried to use the mapRequest configuration to override the body. her an example:
const dataTableOptions = {
apiEndpoint: apiUrl,
requestMethod: "POST",
mapRequest: {
body: (body) => {
console.log("Original Body:", body);

let newBody = {
...body,
idCompany: this.clienteSelezionato.id,
idWallet: this.idWalletSelezionato
};

return newBody;
}
},

No logs are printed.

Can you please help me ?


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (2)


Hi Fabio Drago

Thank you for sharing your solution - it will definitely help others who might face the same issue.



Hello,
the mistake was in the mapRequest body porperty.

The correct way is:
const dataTableOptions = {
apiEndpoint: apiUrl,
requestMethod: "POST",
mapRequest: (query) => {
console.log("Original Query:", query); // Debug per verificare i dati iniziali

query.set('idCompany', this.clienteSelezionato.id);
query.set('idWallet', this.idWalletSelezionato);

console.log("Modified Query:", query); // Debug per verificare che i parametri siano stati aggiunti
return query;
},

Kind regards,
Fabio Drago


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(