Using jQuery tablesorter, I can't get it to do work for my table. Where am I going wrong?

后端 未结 3 1902
醉话见心
醉话见心 2021-01-27 13:35

Hey guys so I am trying to use the jQuery plugin table sorter (tablesorter.com). I made a test page based off their demo and it worked no problem. However now I am trying to imp

相关标签:
3条回答
  • 2021-01-27 13:55

    Put your <tbody> outside the for loops.

    ...
    </thead>
    
    <tbody> 
    <?foreach ($organizations as $organizationObj) {
        foreach ($organizationObj as $curOrg) {
            if($curOrg->get("name") == "System"){
                //Hide the System organization from vCloud 
                continue;
            }?> 
    
        <tr>
            <td><?=$curOrg->get("name");?></td>
            <td><?=$curOrg->get("description")===""?"None":$curOrg->get("description")?></td>
            <td><?=$curOrg->get("systemName")?></td>
            <td><?=$status[$curOrg->get('status')];?></td>
            <td id="client<?=$curOrg->get('id');?>">            
                <?if($curOrg->get("clientId")==0){ ?>
                    <button class="btn btn-tiny btn-reverse associate" data-uid="<?=$curOrg->get('id');?>"><?=$languageDB->berkGet("action_associate");?></button>
                <?} else{ 
                    $client=new client($curOrg->get("clientId"));?>
                    <?=$client->get("companyName");?>
                <?}?>
            </td>
            <td><a href="/organizationDetails.php?id=<?=$curOrg->get('id');?>" class="btn btn-tiny"><i class="fa fa-info-circle"></i></a>
                <?if($curOrg->get("clientId")>0){ ?>
                    <button class="btn btn-danger btn-tiny" id="remove" data-uid="<?=$curOrg->get('id');?>" data-name="<?=$curOrg->get('name');?>"><i class="fa fa-trash"></i> </button>
                <?}?>
        </tr>    
        <?}
    }?>
    </tbody>
    </table>
    
    0 讨论(0)
  • 2021-01-27 14:10

    Use Jquery datatables

    in your case:

    $(document).ready(function() 
        { 
            $("#orgTable").DataTable(); 
        } 
    );
    

    https://www.datatables.net/examples/basic_init/zero_configuration.html

    UPDATE: If you dont want to change ur tablesorter or use any other jQuery plugin for table sorting,check ur <script> tags

    use :

    <script type="text/javascript"></script>

    instead of :

    <script type="text/javascript"/>

    0 讨论(0)
  • 2021-01-27 14:11

    That's because the script tag cannot be a self closing tag

    <script type="text/javascript" src="js/jquery-1.9.1.js"></script> 
    <script type="text/javascript" src="js/jquery.tablesorter.js"></script>
    <script type="text/javascript">
    
    $(document).ready(function() 
        { 
            $("#orgTable").tablesorter(); 
        } 
    ); 
    </script>
    
    0 讨论(0)
提交回复
热议问题