how to apply table sorter for nested headers in table?

自古美人都是妖i 提交于 2020-01-07 06:26:10

问题


in a single table the tablesorter functionality working fine.But i am confusing to apply the table sorter for the below scnario.

ID  Name    Phone
1   vasu    4562789
Role    status  submitted
admin   completed   yes
user    notcompleted    no
2   venkat  78979789
Role    status  submitted
admin   completed   yes
3   balu    768792
Role    status  submitted
user    completed   yes
4   jj  897422
Role    status  submitted
user    completed   no



<script type="text/javascript">
  $("#maintbl").tablesorter();
</script>
<table class="tablesorter" id="maintbl">
<thead>
  <th>id</th>
  <th>name</th>
  <th>phone</th>
  <thead> 
<tbody>
<tr>
  <td><%: id%></td>
  <td><%: name%></td>
<td><%: phone%></td>
</tr>
<tr>
<td>
<table id="childtbl">
<thead>
  <th>appid</td>
  <th>appname</th>
</thead>
<tr>
 <td><%: appid%></td>
 <td><%: appname%></td>
</tr>
</table>  
</td>
</tr>
</table>

like the above my table design is available.I want to apply the sorter functionality.

If i am applying the sorting functionality to "maintbl" the child tables records are not ordering . I need to sort records based on maintbl headers.how to sort the childtable according the maintbl values.i mean need to sort the values based on maintbl only.how to do this?


回答1:


The shared HTML markup won't work because the child table is in a row with only one td and no colspan... Here is how, I think, the markup should look like (demo):

HTML (showing only one entry)

<table class="tablesorter" id="maintbl">
    <thead>
        <th>id</th>
        <th>name</th>
        <th>phone</th>
    </thead>
    <tbody>

        <!-- one parent + child row containing a child table -->
        <tr>
            <td>1</td>
            <td>vasu</td>
            <td>4562789</td>
        </tr>
        <tr class="tablesorter-childRow">
            <td colspan="3">
                <table class="childtbl">
                    <thead>
                        <th>Role</th>
                        <th>Status</th>
                        <th>Submitted</th>
                    </thead>
                    <tbody>
                        <tr>
                            <td>admin</td>
                            <td>completed</td>
                            <td>yes</td>
                        </tr>
                        <tr>
                            <td>user</td>
                            <td>notcompleted</td>
                            <td>no</td>
                        </tr>
                    </tbody>
                </table>
            </td>
        </tr>

    </tbody>
</table>

Script

$(function(){
    $('#maintbl').tablesorter({
        theme: 'blue',
        sortList: [[1, 0]],
        widgets: ['zebra', 'columns']
    });

    $('.childtbl').tablesorter({
        theme: 'blue',
        sortList: [[0, 0]],
        widgets: ['zebra', 'columns']
    });
});


来源:https://stackoverflow.com/questions/22845076/how-to-apply-table-sorter-for-nested-headers-in-table

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