Since the items in table A have a one-to-one correspondence to the items in table B, it's better to use an object to represent this data. An array of these objects represents the entire dataset. Whenever a sort is needed, just sort this array, and repopulate the tables.
// first represents the item in table A
// second represents the item in table B
function Transporter(first, second) {
this.first = first;
this.second = second;
}
Then create a custom sort function that only compares the property first
for sorting an array of Transporter
objects.
function compare(a, b) {
if(a.first < b.first) {
return -1;
}
else if(a.first > b.first) {
return 1;
}
return 0;
}
And a test run:
var transporters = [];
transporters.push(new Transporter("car", "automobile"));
transporters.push(new Transporter("bike", "train"));
console.log(transporters); // [0] => (car:automobile), [1] => (bike:train)
transporters.sort(compare);
console.log(transporters); // [0] => (bike:train), [1] => (car:automobile)
When the sort is done, update both tables.
Or, alternatively use any existing script or plugin. Here's one for jQuery: http://tablesorter.com/docs/