ajax option as a function for server side processing

ajax option as a function for server side processing

KirkulesKirkules Posts: 4Questions: 2Answers: 0

I defined a data function that I'm asigning to the ajax property.

dataFunction(data, callback, settings) {

console.log("draw: " + data.draw + "; order column: " + data.order[0].column + " " + data.order[0].dir + ";");
...
callback({
draw: data.draw,
data: this.leads(), // domData,
recordsTotal: this.leads().length,
recordsFiltered: this.leads().length
});
}

The first time the table is displayed, the dataFunction is called 4 times. If I click on the ordering controls (changes column 0 from asc to desc) it's called at least 2 times. Sometimes with different draw values, sometimes with the same. There's no real ordering I can pattern.

from the console:

draw: 1; order column: 0 asc;
leads.ts:175 draw: 1; order column: 0 asc;
leads.ts:200 did not call setEntities
leads.ts:189 called setEntities
leads.ts:175 draw: 1; order column: 0 asc;
leads.ts:200 did not call setEntities
leads.ts:175 draw: 1; order column: 0 asc;
leads.ts:200 did not call setEntities
leads.ts:175 draw: 2; order column: 0 desc;
leads.ts:175 draw: 1; order column: 0 asc;
leads.ts:200 did not call setEntities
leads.ts:189 called setEntities
leads.ts:175 draw: 2; order column: 1 asc;
leads.ts:200

Can anyone tell me why this function is getting called repeatedly? how to stop it? what I'm doing wrong?

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    Probably should put up more of your code to see if there is an event handler or something else that is triggering this.

  • KirkulesKirkules Posts: 4Questions: 2Answers: 0

    Figured it out in the shower this morning..

    The initialization of the datatable control ishandled inside a custom knockout binding and it was being reinitialized on each update.. I removed the update method and only initialize the control once in init: all is well now.

    Thanks for the support...

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    to funny, I made that exact same mistake.

This discussion has been closed.