te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - Datatables - Responsive not working? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Datatables - Responsive not working? - Stack Overflow

programmeradmin2浏览0评论

I am trying to understand why Datatables (/) Responsive wouldn't be working. Everything else is working great, paging, searching, ordering, etc.. but not responsive?

Below is what I have.

Bootstrap v3.3.6

$(function () {
    $('#ManageUsers').DataTable({
        paging: true,
        lengthChange: true,
        searching: true,
        ordering: true,
        info: true,
        autoWidth: true,
        responsive: true
    });
});
<!-- CSS -->
<link rel="stylesheet" href=".3.6/css/bootstrap.min.css">
<link rel="stylesheet" href=".10.12/css/jquery.dataTables.min.css">
<!-- JS -->
<script src=".2.4.min.js"></script>
<script src=".3.6/js/bootstrap.min.js"></script>

<script src=".10.8/js/jquery.dataTables.min.js"></script>
<script src=".10.8/js/dataTables.bootstrap.min.js"></script>
<script src=".1.0/js/dataTables.responsive.js"></script>


<!-- CODE -->

<table id="ManageUsers" class="table table-bordered table-striped display responsive">
    <thead>
        <tr>
            <th>...</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>...</td>
        </tr>
    </tbody>
</table>

I am trying to understand why Datatables (https://datatables/) Responsive wouldn't be working. Everything else is working great, paging, searching, ordering, etc.. but not responsive?

Below is what I have.

Bootstrap v3.3.6

$(function () {
    $('#ManageUsers').DataTable({
        paging: true,
        lengthChange: true,
        searching: true,
        ordering: true,
        info: true,
        autoWidth: true,
        responsive: true
    });
});
<!-- CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn./bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.datatables/1.10.12/css/jquery.dataTables.min.css">
<!-- JS -->
<script src="https://code.jquery./jquery-2.2.4.min.js"></script>
<script src="https://maxcdn.bootstrapcdn./bootstrap/3.3.6/js/bootstrap.min.js"></script>

<script src="https://cdn.datatables/1.10.8/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables/1.10.8/js/dataTables.bootstrap.min.js"></script>
<script src="https://cdn.datatables/responsive/2.1.0/js/dataTables.responsive.js"></script>


<!-- CODE -->

<table id="ManageUsers" class="table table-bordered table-striped display responsive">
    <thead>
        <tr>
            <th>...</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>...</td>
        </tr>
    </tbody>
</table>

Any help will be greatly appreciated.

Share Improve this question edited Feb 1, 2017 at 12:38 fernandosavio 10.4k4 gold badges25 silver badges34 bronze badges asked Feb 1, 2017 at 6:16 LeviZoeschLeviZoesch 1,6214 gold badges22 silver badges39 bronze badges 6
  • See if you have missed any required file or any file that conflicts. Check one by one. That may lead to help. – AT-2017 Commented Feb 1, 2017 at 6:19
  • ? Not sure I follow? @AT-2016 – LeviZoesch Commented Feb 1, 2017 at 6:30
  • Pls create and show your fiddle – Manoj Commented Feb 1, 2017 at 7:02
  • A codepen or jsfiddle might help us understand what exactly went wrong – Ashish Bahl Commented Feb 1, 2017 at 12:29
  • Any progress with that?@Kray – Offir Commented Feb 5, 2017 at 12:21
 |  Show 1 more ment

4 Answers 4

Reset to default 8

Try loading the libraries in this order like in the DEMO.

<script src="https://cdnjs.cloudflare./ajax/libs/jquery/3.0.0/jquery.js"></script>
<script data-require="datatables@*" data-semver="1.10.12" src="//cdn.datatables/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables/1.10.13/js/dataTables.bootstrap.min.js"></script>
<script src="https://cdn.datatables/responsive/2.1.0/js/dataTables.responsive.js"></script>

<link href="//cdn.datatables/responsive/2.1.1/css/dataTables.responsive.css"/>
<link data-require="datatables@*" data-semver="1.10.12" rel="stylesheet" href="//cdn.datatables/1.10.12/css/jquery.dataTables.min.css" />
<link data-require="bootstrap@*" data-semver="4.0.5" rel="stylesheet" href="https://maxcdn.bootstrapcdn./bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" />
  • You are missing https://cdn.datatables/1.10.12/css/jquery.dataTables.min.css in your header and missed nowrap in class according to their examples.
  • I personally would suggest to initiate responsive dataTable via javascript as it will provide more options to customise your UI.

Please refer to these links for reference https://datatables/extensions/responsive/examples/initialisation/default.html https://datatables/extensions/responsive/examples/initialisation/className.html https://datatables/extensions/responsive/examples/initialisation/option.html

Try using width=100% in table. Not pretty, but it worked for me.

Just use this script at the bottom of your file

<script>
  $(function () {
    $("#manageUsers").DataTable({
            "bLengthChange": false,
            "bPaginate": true,
            "bInfo": false,
            "autoWidth": false, 
            "order": [[0, "desc"]],
            responsive: true,
            "processing": true,
            "serverSide": false,
            "sAjaxSource": "data.js",
            "columns": [
            { "data": "name[, ]" },
            { "data": "hr.0" },
            { "data": "office" },
            { "data": "extn" },
            { "data": "hr.2" },
            { "data": "hr.1" }
    });
  </script>

It worked for me.

发布评论

评论列表(0)

  1. 暂无评论