jquery tablesorter index column insert

烂漫一生 提交于 2019-11-27 09:51:08

I'm not that great with php, but couldn't you just do this?

echo "<table id=\"tabel\" class=\"tablesorter\">
<thead>
<tr>
<th>#</th>";
.
.
.
//next code fetch cells content
echo "<tbody>";

$i=1;

while ($row=pg_fetch_row($result)){
    echo "<tr>";
    echo "<td> $i </td>";
    $i++;

    foreach($row as $_column){
    echo "<td> $_column </td>";
    }
    echo "</tr>";

}

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']
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!