Diff of 2 datatables

Diff of 2 datatables

hpegmslicensemgmthpegmslicensemgmt Posts: 23Questions: 8Answers: 0

Dear all,
Is there a clever way to get the difference between 2 DataTables ?

2 Tables with the same structure and similar content where Table A can have different entires of Table B ...

Best regards,
David

Answers

  • kthorngrenkthorngren Posts: 21,315Questions: 26Answers: 4,948

    You can use rows().data(), possibly with toArray(), to get all the data in the Datatable. Use a loop to iterate the both sets of data to compare for differences.

    Kevin

  • kthorngrenkthorngren Posts: 21,315Questions: 26Answers: 4,948

    Any sorting or searching that is applied differently between the two tables might affect the order the row data is traversed. See the selector-modifier docs to choose the appropriate options for your solution.

    Kevin

  • rf1234rf1234 Posts: 2,988Questions: 87Answers: 421

    Any sorting or searching that is applied differently between the two tables might affect the order the row data is traversed.

    Right! Here is something from my own coding sorting the data so that that they can be compared and eventually diffed.

    var sRows = dt.rows().data().toArray();
    sRows.sort(function(a,b) {
        return a.DT_RowId.localeCompare(b.DT_RowId);
    });
    
Sign In or Register to comment.