SearchBuilder v1.7.0 interferes with server-side ajax requests.

SearchBuilder v1.7.0 interferes with server-side ajax requests.

jpujpu Posts: 17Questions: 5Answers: 0
edited March 26 in Free community support

Description of problem:
SearchBuilder v1.7.0 interferes with server-side ajax requests.
Previously using v 1.3.4 I could convert the datatables data object to be sent to JSON format using a function like:

                "ajax" : {
                    "url": 'https://mytargeturl',
                    "contentType" : "application/json",
                    "type" : 'POST',
                    "data": function(d) {
                        var sb = $('#myTable').DataTable().searchBuilder;
                        var sbDetails = null;
                        try {
                            sbDetails = sb.getDetails();
                        } catch(e) {
                            console.log('SearchBuilder not yet initialised!');
                            sbDetails = {"criteria":[{"condition":"<=","data":"ID","origData":"ID","type":"num","value":["5000"]}],"logic":"AND"}};
                        }
                        if (Object.keys(sbDetails).length > 0) {
                            d.searchBuilder = sbDetails;
                        }
                        return JSON.stringify(d);
                    }

I.e. where normally a FORM is posted I now convert the FORM data to a JSON structure and send an XHR request. This worked well with v1.3.4.
But I recently upgraded to the latest version(s) of datatables and it now uses v1.7.0 of SearchBuilder. The above data function still works but after that searchBuilder.js is still trying to do some stuff on the data which now fails as my function returns a string and not a datatable object.

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:

Uncaught TypeError: can't assign to property "searchBuilder" on "{\"draw\":2,\"columns\":[{\"data\":\"ID\",\"name\":\"Id\",\"searchable\":false,\"orderable\":false,\"search\":{\"value\":\"\",\"regex\":false,\"fixed\":[]}},{\"data\":\"ONDERNEMINGSNUMMER\",\"name\":\"Ondernemingsnummer\",\"searchable\":true,\"orderable\":true,\"search\":{\"value\":\"\",\"regex\":false,\"fixed\":[]}},{\"data\":\"NAAM\",\"name\":\"Naam\",\"searchable\":true,\"orderable\":true,\"search\":{\"value\":\"\",\"regex\":false,\"fixed\":[]}},{\"data\":\"OPSTARTDATUM\",\"name\":\"Opstartdatum\",\"searchable\":true,\"orderable\":true,\"search\":{\"value\":\"\",\"regex\":false,\"fixed\":[]}},{\"data\":\"ADDRESS\",\"name\":\"Adres\",\"searchable\":true,\"orderable\":true,\"search\":{\"value\":\"\",\"regex\":false,\"fixed\":[]}},{\"data\":\"REKENINGNUMMER\",\"name\":\"Rekeningnummer\",\"searchable\":true,\"orderable\":true,\"search\":{\"value\":\"\",\"regex\":false,\"fixed\":[]}},{\"data\":\"ACTIEF\",\"name\":\"Actief\",\"searchable\":true,\"orderable\":true,\"search\":{\"value\":\"\",\"regex\":false,\"fixed\":[]}},{\"data\":\"ID\",\"name\":\"Action\",\"searchable\":false,\"orderable\":false,\"search\":{\"value\":\"\",\"regex\":false,\"fixed\":[]}}],\"order\":[{\"column\":0,\"dir\":\"asc\",\"name\":\"Id\"}],\"start\":0,\"length\":20,\"search\":{\"value\":\"\",\"regex\":false,\"fixed\":[]},\"searchBuilder\":{\"criteria\":[{\"condition\":\"<=\",\"data\":\"ID\",\"origData\":\"ID\",\"type\":\"num\",\"value\":[\"5000\"]}],\"logic\":\"AND\"}}": not an object
_setUp https://cdn.datatables.net/searchbuilder/1.7.0/js/dataTables.searchBuilder.min.js:4

Answers

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin

    That is indeed a problem. What version of DataTables were you using before? I've been looking at this, and I would have expected 1.13.7 and later to have this issue. I haven't looked back at earlier versions yet.

    Allan

  • p001p001 Posts: 1Questions: 0Answers: 0

    I'm having the exact same issue. SearchBuilder versions below v1.7.0 seem to be in-compatible w/ DataTables v2 so downgrading as a quick fix isn't easy as one would have to find versions of various other add-ons that work w/ each other. Is there a SearchBuilder v.1.8 in the works that would address this issue?

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin

    Not yet there isn't, but it is something that I will be looking into when I can.

    Allan

  • jpujpu Posts: 17Questions: 5Answers: 0

    Well I initially made this as a demo for a customer 2 years ago and then I was using v1.12.1 of DataTables with v1.3.4 of SearchBuilder.
    Due to the renewed interest I tried to update the demo using the latest libraries: v2.0.3 of Datatables and v1.7.0 of SearchBuilder and hit on above problem.

Sign In or Register to comment.