jquery tablesorter index column insert

后端 未结 1 1262
我在风中等你
我在风中等你 2020-12-02 03:12

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

1条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 03:38

    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++;
    
        foreach($row as $_column){
        echo "";
        }
        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 讨论(0)
    提交回复
    热议问题
    #
    $i $_column