render method loading issue

render method loading issue

dweedendweeden Posts: 5Questions: 2Answers: 0
edited May 2021 in DataTables 1.10

New user trying to override render functionality for the 7th column of a server side generated data set with anonymous columns names.

The function below derived from the example works fine if I use replace but replaceAll causes it to hang on loading.

I can probably work around this within a loop that checks manually if there's more work to do but I'd rather the 'All' method of this and matchAll be at my disposal.

Also, is there syntax that'd allow me to just override the 7th column rather than providing placeholders as I've done below?

Dave

$(document).ready(function() {

        $('#example').DataTable( {
            "ajax": "api/Grid/1", columns: [{}, {}, {}, {}, {}, {}, {}, { 
                render: function(data, type) {
                     if (type === 'display') {

                        let test = String('one fish, two fish, red fish, blue fish');

                        test = test.replaceAll(/fish/, 'foo')

                        return test;
                     }

                     return data;
                }
            } ]
        } )
    });

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949
    edited May 2021 Answer ✓

    but replaceAll causes it to hang on loading.

    I put your code into this test case:
    http://live.datatables.net/cinehamu/1/edit

    You will see this error in the browser's console:

    Uncaught TypeError: String.prototype.replaceAll called with a non-global RegExp argument

    Anytime the Datatable doesn't seem to load properly or have the proper formatting look in the browser's console for errors.

    The replaceAll() docs state this:

    regexp (pattern)
    A RegExp object or literal with the global flag. The matches are replaced with newSubstr or the value returned by the specified function. A RegExp without the global ("g") flag will throw a TypeError: "replaceAll must be called with a global RegExp".

    Here is the working example with the global flag:
    http://live.datatables.net/kulahire/1/edit

    Also, is there syntax that'd allow me to just override the 7th column rather than providing placeholders as I've done below?

    You can use columnDefs which I have in the example.

    Kevin

  • dweedendweeden Posts: 5Questions: 2Answers: 0

    Awesome! Many thanks :)

This discussion has been closed.