Server side processing with a promise (or delaying the response)

Server side processing with a promise (or delaying the response)

emepycemepyc Posts: 8Questions: 2Answers: 0

Hi,
I'm trying to set up server-side processing serving the data with a promise. This is what I have tried so far:

            "ajax": function (data, cbak, params) {
                var opts = {
                    disease: "EFO_0000270",
                    outputstructure: "flat",
                    facets: true,
                    direct: false,
                    size: data.length,
                    from: data.start,
                    sort: order,
                    draw: 1
                };

                apiService.getAssociations(opts)
                    .then (function (resp) {
                        var dtData = parseServerResponse(resp.body.data);
                         var o = {
                            recordsTotal: resp.body.total,
                            recordsFiltered: resp.body.size,
                            data: dtData,
                            draw: 1
                        };
                        cbak(o);
                    });
            },

This is not working, but I think I'm missing something more obvious here, since this is not working either:

            "ajax": function (data, cbak, params) {
   
             var mockData = {
                    recordsTotal: 4,
                    recordsFiltered: 4,
                    draw: 1,
                    data: [
                        ["kk", "kk", 1,1,1,1,1,1,1,1,1,1,"kk"],
                        ["kk", "kk", 1,1,1,1,1,1,1,1,1,1,"kk"],
                        ["kk", "kk", 1,1,1,1,1,1,1,1,1,1,"kk"],
                        ["kk", "kk", 1,1,1,1,1,1,1,1,1,1,"kk"]
                    ]
                };

             setTimeout(function () {
                   cbak (mock);
             }, 2000)

Of course when I don't delay the cbak(mock) call, the data is renderer.
Since the "ajax" function above is called asynchronously, I don't know why I can't call cbak at any time. Can anyone help me understand this?

M;

This discussion has been closed.