【问题标题】:how i can hide the first column of datatables?如何隐藏数据表的第一列?
【发布时间】:2015-04-07 13:55:35
【问题描述】:

我有一张表,我想隐藏一列,我尝试了很多方法,这就是其中之一

jQuery:

var table = $('#client').DataTable({
responsive: true,
language: {
    url: '../DataTables/media/js/French.json'
},
"columnDefs": [
    { "visible": false, "targets": 0 }]
});

PHTML:

    <table id="client" class="display" cellspacing="0" width="100%">
        <input type="hidden" value="<?php echo $typeProfile;?>" id="idProfilSession"/>
        <thead>
            <tr>
                <th> N° client </th>
                <th> Société</th>
                <th> Nom </th>
                <th> Prénom </th>
                <th> Email</th>
                <th> Fixe </th>
                <th> Mobile </th>
                <th  align="center"> Action </th>
        <?php
            //if($accesAction){?>
                <!-- <th> Supprimer </th>  -->
                <!-- <th> Modifier </th>  -->
        <?php
            //}
            //if($accesCommentaire){
        ?>
                <!-- <th> Commentaire </th>  -->
        <?php //}?>
            </tr>
        </thead>
        <tbody>
            <?php
            foreach ($this->clients as $key => $client)
            {
                ?>
                <tr>
                    <td class='numClientCol'><?php echo $client->id; ?></td>
                    <td>
                        <?php echo ucfirst($client->Societe->nom); ?>
                        <button class="AfficherModifierSociete btn btn-default"
                                data-toggle="modal"
                                data-target="#formModifSociete"
                                data-whatever="@mdo"
                                data-id="<?php echo $client->Societe->idsociete;?>"
                                type="button" style="padding:0;padding:0;">
                            <a href="<?php echo $this->baseUrl() ?>/commentaire/index/idClient/<?php echo $client->id; ?>">
                                <img class="info-societe"
                                    style='height:25px;border:none;padding:0;padding:0;'
                                    title='modifier société'
                                    src='../images/editer-societe.png'/>
                            </a>
                        </button>
                    </td>
                    <td><?php echo $client->nom; ?></td>
                    <td><?php echo $client->prenom; ?> </td>
                    <td><?php echo $client->email; ?></td>
                    <td><?php echo $client->tel_fixe; ?> </td>
                    <td><?php echo $client->tel_mobile; ?> </td>
                    <td class="action "align="center">
                        <div class="btn-group" role="group" aria-label="...">
                            <?php if($accesAction){?>
                                <button type="button" class="supprimerClient btn btn-default" style="padding:0;padding:0;">
                                    <img type="button" class="supprimerClient btn btn-default" title='Supprimer' src='../images/supprimer.png' style='height:25px;border:none;padding:0;padding:0;cursor: pointer;'/>
                                </button>
                                <button data-toggle="modal"
                                        data-target="#formModifClient"
                                        data-whatever="@mdo"type="button"
                                        class="modifierClient btn btn-default" style="padding:0;padding:0;">
                                    <img title='Modifier'
                                          src='../images/modifier.png'
                                          style='height:25px;border:none;padding:0;padding:0;'/>
                                  </button>
                            <?php }?>
                            <?php if($accesCommentaire){ ?>
                                <a type="button" class="btn btn-default" style="padding:0;padding:0;" href="<?php echo $this->baseUrl() ?>/commentaire/index/idClient/<?php echo $client->id; ?>">
                                    <img style='height:25px;border:none;padding:0;padding:0;cursor: pointer;' alt="" src="../images/addCommentaire.png">
                                </a>
                            </button>
                            <?php }?>
                        </div>
                    </td>
                </tr>
                <?php
            }
            ?>
        </tbody>
</table>

我想隐藏此列“N° 客户端”,但没有 CSS 或 javascript,只是带有选项 datables...

还有其他方法可以隐藏列吗?

【问题讨论】:

  • 试用:{ "visible": false, "targets": [0] }
  • 使用"targets": [0] 而不是"targets": 0
  • @Daan 我试过但没用
  • 创建一个 JSFiddle 作为例子来展示你在做什么。如果您将 0 更改为 [0],您拥有它的方式应该可以工作

标签: php jquery database zend-framework jquery-datatables


【解决方案1】:

也许不是数据表的方式,但您也可以使用 css:

th:first-child,
td:first-child {
  display: none;
}

【讨论】:

  • 谢谢你的回答,但我想用数据表来做这个
  • @AhmedZiani 它也适用于数据表,您尝试过还是需要为此使用 javascript?
  • 我知道,我可以用 css 或 jquery 做到这一点,但我使用 columnDefs 隐藏列
  • @AhmedZiani 太糟糕了:-)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-11-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-04
  • 1970-01-01
  • 1970-01-01
  • 2011-08-05
相关资源
最近更新 更多