Fixed Table
by kapantzak
HTML
<span id="result">nothing</span>
JavaScript
var fixedColArray = [
{
tableId: 'first-table',
active: '1',
col1: {
class: 'st-hide',
active: '1',
width: '40'
},
col2: {
class: 'st-id',
active: '1',
width: '45'
}
},
{
tableId: 'second-table',
active: '0',
col1: {
class: 'st-hide',
active: '0',
width: '50'
},
col2: {
class: 'st-id',
active: '1',
width: '45'
}
}
]
var getTableObj = function(tableId) {
var resultArray = $.grep(fixedColArray, function(e) {
//Returns a new array with the selected item
return e.tableId == tableId;
});
if (resultArray.length == 0) {
return 'no results';
} else if (resultArray.length == 1) {
console.log(resultArray[0].active);
$.each(resultArray[0], function(index, value) {
var activeCol = value.active;
var width = value.width;
if ((activeCol) && (width)) {
console.log(activeCol + ' - ' + width);
}
});
} else {
return 'two or more table objects have the same tableId';
}
}
getTableObj('second-table');