【问题标题】:json tables data how to limit length of td?json表数据如何限制td的长度?
【发布时间】:2016-03-02 14:34:18
【问题描述】:

我编辑了这个表,我用 data.json 文件下载了它,我让它通过 foreach 从数据库中获取数据

我正在使用 Codeigniter 3

这是表格代码

<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-body">
                <table data-toggle="table" data-show-toggle="true" data-show-columns="true" data-search="true" data-select-item-name="toolbar1" data-pagination="true" data-sort-name="name" data-sort-order="desc">
                    <thead>
                    <tr>
                        <th data-field="state" data-checkbox="true" >Post ID</th>
                        <th data-field="id" data-sortable="true">Post ID</th>
                        <th data-field="username"  data-sortable="true">Poster Author</th>
                        <th data-field="post" data-sortable="true">Post</th>
                        <th data-field="tid" data-sortable="true">Topic ID</th>
                        <th data-field="pdate" data-sortable="true">Post Date</th>
                    </tr>
                    </thead>
                    <tbody>
                        <?php
                        foreach ($posts as $post) {
                        echo '
                        <tr>
                        <td>'.$post->pid.'</td>
                        <td>'.$post->pid.'</td>
                        <td>'.$post->author_name.'</td>
                        <td>'.$post->post.'</td>
                        <td>'.$post->topic_id.'</td>
                        <td>'.unix_to_human($post->post_date).'</td>
                        </tr>';
                        }
                        ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div><!--/.row-->  

我的问题是我想限制 post td 的最大长度

<td>'.$post->post.'</td>

有可能吗?

【问题讨论】:

标签: php mysql json codeigniter


【解决方案1】:

在`相关中添加一个内联样式(或者设置一个class stlyle并添加这个类)

  <th style="maxwidth: 100px;"  data-field= .........>

【讨论】:

    【解决方案2】:

    加载文本助手,而不是使用 character_limiter($str[, $n = 500[, $end_char = '&amp;#8230;']]) 喜欢:

    $string = "Here is a nice text string consisting of eleven words.";
    $string = character_limiter($string, 20);
    // Returns:  Here is a nice text string
    

    或者在你的情况下:

    character_limiter($post->post, 100, '&#8230;');// You should set appropriate length
    

    Docs.

    【讨论】:

      猜你喜欢
      • 2015-09-13
      • 2020-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-22
      • 1970-01-01
      相关资源
      最近更新 更多