datatable serverSide_ dataSrc mapping _ some problem

datatable serverSide_ dataSrc mapping _ some problem

zigomariozigomario Posts: 2Questions: 0Answers: 0

Hello,

i get data from ajax and i need to apply JSON.parse before.
So i want use dataSrc like documentation explain.

If i do

                dataSrc: function (json) {
                    let jsonParse = JSON.parse(json)
                   return  jsonParse.data
                },

It's ok to populate Table... but i don't have draw, recordsFiltered, recordsTotal ( parts of my response Ajax).
It's normal..doc is clear with that.

So..i try to map src like doc explain :
__
Each mapping value may be a string in Javascript dotted object notation or a function. If a function a single parameter is passed in, the JSON response from the server, and the return value should be the value for the parameter
__

                dataSrc : {
                    data : function (json){
                        console.log('here')
                        let jsonParse = JSON.parse(json)
                        return  jsonParse.data
                    },
                    draw: function(json){
                        console.log('allo')
                    } ,
                    recordsTotal: 1,
                    recordsFiltered: 1
                },

This time, nothing happen... console.log are not display.

So.... why mapping don't work ?
And if mapping is broken,,...how i can display recordsFiltered/recordsTotal when i need to JSON.parse() my response Ajax

Replies

  • allanallan Posts: 63,434Questions: 1Answers: 10,458 Site admin

    Hi,

    Just to check, are you using DataTables 2? Also, each property, when used like this, should be a function, and each would need to do a JSON.parse - e.g.:

    dataSrc: {
      data: str => JSON.parse(str).data,
      draw: str => JSON.parse(str).draw,
      ...
    }
    

    etc.

    i don't have draw, recordsFiltered, recordsTotal ( parts of my response Ajax).

    Then that isn't enough information to populate a DataTable in server-side processing mode. You need that information so it can know how many pages to offer the end user, etc.

    Is the server actually doing server-side processing for this data? I.e. is it sorting, filtering and paging the data, per the documentation here?

    Allan

  • zigomariozigomario Posts: 2Questions: 0Answers: 0

    Yesssss thank you , i love you !!
    Old local bundle datatable , impossible to know version.
    But with recent cdn ( 2.x)... all is ok !

Sign In or Register to comment.