dataSrc not getting called in editor.

dataSrc not getting called in editor.

MustangProgrammerMustangProgrammer Posts: 16Questions: 5Answers: 0

While working on a project, I was attempting to do an update using the datatables editor with ajax. Here is a snippet:

 editor = new $.fn.dataTable.Editor({
        idSrc: "lites_id",
        ajax: {
            url: 'myAspxPage.aspx/updateTxtData',
            type: 'POST',
            dataType: 'json',
            contentType: "application/json; charset=utf-8",
            dataSrc: function (json) {
                var data = JSON.parse(json.d);
                return data;
            },
            data: function (d) {
                var dataToSend = {};
                var key = Object.keys(d.data)[0];
                var val = d.data[key];
                dataToSend.lites_id= val.lites_id;
                dataToSend.contact_num= val.contact_num;
                dataToSend.provider_id= val.provider_id;

                return JSON.stringify(dataToSend);
            }
        },
.
.
.

The update works as expected, but the return data from the code behind does not trigger the dataSrc section, causing my data not to refresh. Any ideas? .

capture of data returned: {"d":"{\"data\":[{\"lites_id\":1900137,\"first_name\":\"Olr\",\"last_name\":\"Library Common PC\",\"contact_num\":\"111/222-3333\",\"provider_id\":\"alltel\"}]}"}

Both myself and a co-worker has the same issue. They also have a version, in another application that works using something similar to above. We do not understand why this one does not work.

Would this be a better candidate to use: ajax: function (method, url, d, successCallback, errorCallback)?

Any help is greatly appreciated.

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 20,141Questions: 26Answers: 4,736
    edited May 2023 Answer ✓

    It doesn't look like the Editor ajax options have a dataSrc option. In that case you will probably need to use ajax as a function like the last example in the docs.

    Kevin

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin
    Answer ✓

    Correct - there is no ajax.dataSrc option for Editor. It will send and receive data in the format described in the manual.

    I think Kevin is correct (as always) - in this case, since you are sending data in a different format and returning it back in a different format, you'd be best using ajax as a function. Then you can parse the JSON and call the callback function with the resulting JSON.

    Allan

  • MustangProgrammerMustangProgrammer Posts: 16Questions: 5Answers: 0

    Not a problem, just hoping I could use it instead of the ajax as a function. Thanks all.

Sign In or Register to comment.