I have a PHP generated table from a postgres query. How can I insert an index column with numbered rows at the beginning of the table using tablesorter plugin? The sorting w
I'm not that great with php, but couldn't you just do this?
echo "
# ";
.
.
.
//next code fetch cells content
echo " ";
$i=1;
while ($row=pg_fetch_row($result)){
echo "";
echo " $i ";
$i++;
foreach($row as $_column){
echo " $_column ";
}
echo " ";
}
If you want a that column to not sort and stay unchanged, you can use the following widget (demo) with header option to prevent sorting:
// target the number column using a zero-based index
var number_column = 0;
// add custom numbering widget
$.tablesorter.addWidget({
id: "numbering",
format: function(table) {
var c = table.config;
$("tr:visible", table.tBodies[0]).each(function(i) {
$(this).find('td').eq(number_column).text(i + 1);
});
}
});
$("table").tablesorter({
theme: 'blue',
// prevent first column from being sortable
headers: {
0: { sorter: false }
},
// apply custom widget
widgets: ['numbering']
});
讨论(0)
- 热议问题