Comparing two table values
Comparing two table values
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?
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?
This discussion has been closed.
Replies
[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.