datatables - 排序图标重复

时间:2015-07-29 02:56:50

标签: javascript jquery django datatables

我正在尝试设置此处找到的数据表示例 -

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

一切都很成功,但由于某种原因,排序图标是重复的,我不知道为什么。

这就像它显示的那样 -

这是我正在使用的HTML -

{% extends "dashboard/base.html" %}

{% load static %}

{% block extra_head %}

    <!-- Tribal CSS -->
    <link href="{% static "css/plugins/tribal/tribal-bootstrap.css" %}" rel="stylesheet" />
    <link href="{% static "css/plugins/tribal/tribal-form.css" %}" rel="stylesheet" />

    <!-- Tribal JS -->
    <script src="{% static "js/plugins/tribal/tribal-form.js" %}"></script>
    <script src="{% static "js/plugins/tribal/tribal-shared.js" %}"></script>

    <!-- DataTables CSS -->
    <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.7/css/jquery.dataTables.css">

    <!-- DataTables -->
    <script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"></script>

    <script type="text/javascript" charset="utf-8">
    $(document).ready(function() {
        $('#files').DataTable();
    } );
    </script>

{% endblock %}

{% block title %}{{ user }} Dashboard{% endblock %}

{% block content %}

            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-header">Profile</h1>
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <div class="container">
                <div class="well">
                    <dl class="dl-horizontal dl-multicolumn" data-colcount="3">
                        <dt>Name</dt>
                        <dd>{{ user }}</dd>
                        <dt>Gender</dt>
                        <dd>Male</dd>
                        <dt>School</dt>
                        <dd>Sheffield School</dd>
                        <dt>DOB</dt>
                        <dd>01/01/1986</dd>
                        <dt>Email</dt>
                        <dd>{{ user }}</dd>
                        <dt>Address</dt>
                        <dd>
                            26 Main Road<br />
                            Sheffield<br />
                            S1 1AA</dd>
                    </dl>
                </div>
            </div>
            <!-- /.row -->
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-header">File Access</h1>
                </div>
                <!-- /.col-lg-12 -->
            </div>

                    <div class="panel panel-default">
                        <div class="panel-heading">
                            File & Vendor Listings
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover" id="files">
                                    <thead>
                                        <tr>
                                            <th>Vendor</th>
                                            <th>Filename</th>
                                            <th>Invoke Date</th>
                                            <th>Revoke Date</th>
                                            <th>CSS grade</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td>Trident</td>
                                            <td>Internet Explorer 4.0</td>
                                            <td>Win 95+</td>
                                            <td class="center">4</td>
                                            <td class="center">X</td>
                                        </tr>

我正在使用django所以jquery正在从base.html扩展,就像这样 -

<!DOCTYPE html>
<html lang="en">

{% load static %}

{% if user.is_authenticated %}

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>{% block title %}datapi.io Company Dashboard{% endblock %}</title>

    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">

    <!-- MetisMenu CSS -->
    <link href="{% static "css/plugins/metisMenu/metisMenu.min.css" %}" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="{% static "css/sb-admin-2.css" %}" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- jQuery -->
    <script src="//code.jquery.com/jquery-2.1.4.min.js"></script>

    <!-- Latest compiled and minified JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

    <!-- Metis Menu Plugin JavaScript -->
    <script src="{% static "js/plugins/metisMenu/metisMenu.min.js" %}"></script>

    <!-- Custom Theme JavaScript -->
    <script src="{% static "js/sb-admin-2.js" %}"></script>

    {% block extra_head %}{% endblock %}

</head>

3 个答案:

答案 0 :(得分:8)

SB Admin主题包括DataTables的Bootstrap附加组件。

但是,您发布的代码包括默认的DataTables CSS。在这种情况下,应包括一个或另一个。

解决方案是将默认DataTables CSS(//cdn.datatables.net/1.10.7/css/jquery.dataTables.css)替换为dataTables.bootstrap.css并添加dataTables.bootstrap.min.js

如果您更喜欢使用默认的DataTables CSS,则需要修改sb-admin-2.css - 232行周围的257并删除与table.dataTable相关的规则。

答案 1 :(得分:0)

此解决方案由Elfayer解决。

渲染器:{“ header”:“ bootstrap”},

答案 2 :(得分:0)

上述解决方案对我不起作用。我找到了对我有用的解决方案,

"initComplete": function(settings, json) {
   $('.dataTables_scrollBody thead tr').css({visibility:'collapse'});
}

https://github.com/DataTables/Plugins/issues/159#issuecomment-333897227