Comparing two table values

Comparing two table values

VidyaVidya Posts: 1Questions: 0Answers: 0
edited October 2011 in General
Hello,
How do i compare rows of two different datatables to find if they have the same value? Basically, I have a popup window which shows all selected check-box values in the window. In this popup window, user can further deselect any check-box. I need this change to be reflected back into the parent window.
Can somebody please help me here?

Replies

  • OmnimikeOmnimike Posts: 22Questions: 0Answers: 0
    Do the rows have some kind of unique id column you can use to look them up? If so you can do something like this:
    [code]
    var mainTable = $('#mainTableId').dataTable();
    var windowTable = $('#windowTableId').dataTable();
    var allDataInMainTable = mainTable.fnGetData();
    var allDataInWindowTable = windowTable.fnGetData();
    for (var i in allDataInMainTable) {
    var mainData = allDataInMainTable[i];
    for (var j in allDataInWindowTable) {
    var windowData = allDataInWindowTable[j]'
    if (mainData.id == windowData.id)
    mainWindow.fnUpdate(windowData, i);
    }
    }
    [/code]
    If they don't have a column with a unique id you would have to do something other than "mainData.id == windowData.id" to tell if they were the same row.

    Personally I would use something like Backbone.js models and have the grids bind to change events to keep themselves in sync, though if you aren't already using backbone doing something like that is probably overkill for what you are trying to accomplish.
This discussion has been closed.