I folks, I have following javascript function, which should check for the index of a column in a table. The problem is the comparison of the columnName and the name from the table. I have tested with columnName 'ID' and this column is found in the table, but the comparison is not true, so that the index is not returned.
My code:
function getColumnIndex(columnName, grid) {
console.log("loading column index for column: [" + columnName + "]");
$('div.hDivBox > table > thead > tr > th', grid).each(function(index) {
var name = $(this).attr('title');
console.log("Checking cell: [" + name + "]");
if (String(name) == columnName) {
return index;
}
});
console.log("no cell found with name: " + columnName);
return -1;
}
The log statements:
loading column index for column: [ID]
Checking cell: [ID]
Checking cell: [Name]
Checking cell: [Description]
Checking cell: [AddTime]
Checking cell: [UpdTime]
no cell found with name: ID
An example of the HTML, which is analyzed by the javascript function:
<div class="hDivBox">
<table cellspacing="0" cellpadding="0">
<thead>
<tr>
<th align="center" hidden="" axis="col0" title="ID" style="display: none;">
<div style="text-align: center; width: 30px;">ID</div>
</th>
<th align="center" axis="col1" title="Name" class="">
<div style="text-align: center; width: 250px;">Name</div>
</th>
<th align="center" axis="col2" title="Description" class="">
<div style="text-align: center; width: 250px;">Beschreibung</div>
</th>
<th align="center" axis="col3" title="AddTime">
<div style="text-align: center; width: 120px;">hinzugefügt</div>
</th>
<th align="center" axis="col4" title="UpdTime">
<div style="text-align: center; width: 120px;">aktualisiert</div>
</th>
</tr>
</thead>
</table>
String(name)as it's already a string. Also, be sure when you are talking about ID, name and title - they are all different attributes!String(name) == String(columnName)though I doubt that'll change anything