JS Exception after removing a row using Editor

JS Exception after removing a row using Editor

FrknFrkn Posts: 7Questions: 3Answers: 0

Hey! I used datatables + editor multiple times in different projects and i got this strange exception for the first time.

When deleting the row, the ajax request is sent to the server with a successful response and the row is removed from the server. But now when the datatable is updating, it seemingly has problems with the removed row. It happens all the time and it doesnt matter which row i'm deleting.

Exception: Uncaught TypeError: ctx[0].aoData[this[0]] is null (dataTables.mjs:8140:2)

Code snippet from dataTables.mjs 8135 to 8143:

_api_register( _child_obj+'.isShown()', function () {
    var ctx = this.context;

    if ( ctx.length && this.length ) {
        // _detailsShown as false or undefined will fall through to return false
        return ctx[0].aoData[ this[0] ]._detailsShow || false; // <-- exception happens here
    }
    return false;
} );

At this point of the exception, ctx[0].aoData[ this[0] ] is null because it is the removed row. When inspecting ctx[0].aoData, i see all the rows as objects with data in them except the index of the removed row, which is null.

The comment above the exception line also mentions that "it should fall through to return false if _detailsShow is undefined". Maybe it was intended that the row object can be undefined/null at this point but it's not handled correctly?

Answers

  • allanallan Posts: 63,678Questions: 1Answers: 10,497 Site admin

    Are you able to give me a link to a page showing the issue please? I've not encountered that error before and would be interested to see if I can identify what is causing the issue so I can add a unit test for it.

    Thanks,
    Allan

  • FrknFrkn Posts: 7Questions: 3Answers: 0

    I got the issue fixed :)

    For anyone stumbling upon this in future:

    My problem was that yarn locked 2 versions of datatables.net-dt (in my case 2.0.3 and 2.1.3), so that the assets bundler (vite) included both versions into the js file. So i locked both datatables.net and datatables.net-dt on specific versions (2.1.3) via resolutions in the package.json.

    I had these kind of problems before with jQuery as well, where Datatables logged all kind of errors if there are 2 jQuery versions bundled in the js.

  • allanallan Posts: 63,678Questions: 1Answers: 10,497 Site admin

    Interesting. Many thanks for letting us know.

    Allan

Sign In or Register to comment.