jquery tablesorter索引列插入

我有一个来自postgres查询的PHP生成表。 如何使用tablesorter插件在表的开头插入带有编号行的索引列? 分拣工作。 谢谢。

klejgkekrj

qwef

         $(function(){ $("#tabel").tablesorter({ widgets: [ 'zebra' , 'filter' ] }) });    <?php $con = pg_connect("user=* password=* host=localhost port=5432 dbname=users ") or die (pg_last_error()); $query = "SELECT * from users"; $result = pg_query($con, $query); echo ""; //next code get column names for($i=0; $i < pg_num_fields($result); $i++){ $field_info = pg_field_name($result, $i); echo ""; } echo " "; //next code fetch cells content echo ""; while ($row=pg_fetch_row($result)){ echo ""; foreach($row as $_column){ echo ""; } echo ""; } echo "
$field_info
$_column
"; pg_close($con); ?>

我用php不是那么好,但你不能这样做吗?

 echo ""; . . . //next code fetch cells content echo ""; $i=1; while ($row=pg_fetch_row($result)){ echo ""; echo ""; $i++; foreach($row as $_column){ echo ""; } echo ""; }
#
$i $_column

如果您希望该列不排序并保持不变,则可以使用以下具有标题选项的小部件( 演示 )来防止排序:

 // 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'] });