DataTables / DataTablesSrc

DataTables source repository
https://datatables.net
MIT License
587 stars 422 forks source link

Exception thrown when column is invisible and row got removed and immediately draw() called #266

Closed AndOne1974 closed 3 months ago

AndOne1974 commented 3 months ago

https://github.com/DataTables/DataTablesSrc/blame/0e78039c4ae0e473be363a87ceecce74b0d4673c/js/core/core.internal.js#L159

If a[ order[i] ] is null than an exception is thrown. This can happen if serverSide rendering = true, the column is invisible and the row got removed by rows(.selected").remove().draw().

fix:

if ( a[ order[i] ] && a[ order[i] ][ prop ] ) { out.push( a[ order[i] ][ prop ][ prop2 ] ); }

should be the same if() as in _pluck

AllanJard commented 3 months ago

Hi - thanks for this!

rows(.selected").remove().draw().

If you are using server-side processing, you wouldn't typically use rows().remove() since that is a client-side action. It has no effect on the server-side data.

Are you able to give me a link to a page showing the issue please?

AndOne1974 commented 3 months ago

Well i call it on the client side to remove the row immediately and afterwards i do an ajax call to remove the record in the db.

AndOne1974 commented 3 months ago

btw the remove() set the record in hashmap to null but the draw() failed with an exception. It has nothing to do with the serverside, it is simply a client side issue if the column is not visible. You cannot check for prop if a[ order[i] ] is undefined.

AllanJard commented 3 months ago

Can you give me a link to a test case showing the issue so I can add it to the unit tests please? There is something more going on than just a cell in a hidden column and a row being removed, as that works fine as shown here: https://live.datatables.net/xixawalo/1/edit .

AllanJard commented 3 months ago

Oops - didn't mean to close this before. pressed the wrong button!

AndOne1974 commented 3 months ago
AndOne1974 commented 3 months ago

https://live.datatables.net/xixawalo/2/edit

here is the working example of the error:

dataTables.js:8188 Uncaught TypeError: Cannot read properties of null (reading '_detailsShow') at _Api. (dataTables.js:8188:36) at Function.isShown (dataTables.js:6810:17) at _Api. (dataTables.responsive.min.js:4:2521) at _Api. (dataTables.js:9523:9) at _Api.iterator (dataTables.js:6720:17) at _Api. (dataTables.js:9516:16) at _Api.every (dataTables.js:6810:17) at HTMLTableElement. (dataTables.responsive.min.js:4:2493) at HTMLTableElement.dispatch (jquery-3.7.1.min.js:2:40035) at v.handle (jquery-3.7.1.min.js:2:38006)

AndOne1974 commented 3 months ago

@AllanJard do you need more info about the error?

AllanJard commented 3 months ago

Thank you for the example! Based on that, here is a way to reproduce it without the extensions: https://live.datatables.net/nisokizi/23/edit .

I think it is this block that is the error rather than the pluck function. I'll write a test and check it out.

AllanJard commented 3 months ago

I've committed this fix for that. I think the server-side processing "optimisation" could actually lead to a whole load of similar bugs. Per the comment there, I don't really expect client-side operations like this when using server-side processing, but it removes code to fix it, so that seems good to me :)

AndOne1974 commented 3 months ago

Thx @AllanJard !