call datatable ajax method explicitely with server side processing

call datatable ajax method explicitely with server side processing

yash27yash27 Posts: 3Questions: 2Answers: 0

I am using datatables in my angular application with server side processing which is working fine for me.

my datatable having following options

  options = {
    sDom: 'rt',
    serverSide: true,
    ajax: (dataTablesParameters: any, callback) => {
      this.http
        .post(
          this.url,
          dataTablesParameters
        ).subscribe(( resp : any) => {
          resp = resp.json();
          callback({
            recordsTotal: resp.recordsTotal,
            recordsFiltered: resp.recordsFiltered,
            data: resp.data
          });
        });
    },
    columns: [
      { data: "id" },
      { data: "firstName" },
      { data: "lastName" }
    ],
    scrollY: `calc(100vh - ${$("#header").height() + 85}px)`,
    scroller: { loadingIndicator: true , displayBuffer: 2 },
  };

if you can see, there's an ajax property with two parameters datatableParameters and callback. Is there any way that I can call the ajax property of datatable explicitly, like if I click any button in web page, then it should come over the ajax function with both the parameters I have mentioned with it. Because I want to make http call with the callback function and datatableParameters.

In my case I'm using server side processing with scroller, when I scroll it is calling ajax function with both the parameters. I want the same with my explicit button click event. Something like control should come back to the same ajax function in datatable options when I click to a button. Is it possible, either with jQuery or something else.

Sign In or Register to comment.