【问题标题】:put sorting image in left side of DataTable header将排序图像放在数据表标题的左侧
【发布时间】:2017-01-19 12:45:32
【问题描述】:

我在我的代码中使用DataTable。在这种情况下,表格标题中的排序图像位于标题右侧,标签位于左侧。同样如下:

我想交换它并将标题标签放在正确的位置。我该怎么办? 我的html表格代码:

<table  id="example" class="display" cellspacing="0" width="100%">
    <thead >
    <tr>
        <th >عکس</th>

        <th>نام</th>
        <th>نام خانوادگی</th>
        <th>آدرس منزل</th>
        <th>ویرایش</th>
        <th>حذف</th>

    </tr>
    </thead>
</table>

和java脚本代码:

table = $('#example').DataTable({
    select: {
        style: 'multi',
    },

    "aaData": data,
    aaSorting: [[2, 'asc']],
    columns: [
        {
            "width": "3%",
            data: null,
            className: "center",
            "orderable": false,
            defaultContent: '<img class="img-responsive"  src="" />'
        },
        {"width": "27%"},
        {"width": "27%"},
        {"width": "37%"},
        {
            data: null,
            "width": "3%",
            className: "center",
            "orderable": false,
            defaultContent: '<p data-placement="top" data-toggle="tooltip" title="Edit"><button id="EditStudent" class="btn btn-primary btn-xs" data-title="ویرایش"  ><span class="glyphicon glyphicon-pencil"></span></button></p></td>'
        },
        {
            data: null,
            "width": "3%",
            "orderable": false,
            defaultContent: '<p  data-placement="top" data-toggle="tooltip" title="Delete"><button id="DeleteStudent" class="btn btn-danger btn-xs" data-title="Delete"  ><span class="glyphicon glyphicon-trash"></span></button></p>'
        },
        {

            "visible": false,
            "searchable": false
        },

    ]
});

【问题讨论】:

  • 能否分享您的代码?
  • 粘贴一些代码,以便我们为您提供帮助。

标签: jquery html css datatables


【解决方案1】:

使用这个CSS:

table.dataTable thead .sorting {
    text-align: right;
}

table.dataTable thead .sorting_asc {
    text-align: right;
}

table.dataTable thead .sorting_desc{
    text-align: right;
}

【讨论】:

    【解决方案2】:

    试试这个

    table.dataTable thead .sorting::after {
        bottom: 0 !important;
        left: 10px !important; 
        right: 0px !important;
    }
    

    这对你有帮助,谢谢

    【讨论】:

    • 这只是把没有排序的图像放在左边,但标题图像又被留下了。并且排序的列的图像现在是正确的。
    • 如果您希望标题值向右移动,则此 css 应仅适用于排序图像,然后为此编写更多 css
    • 但是当我更改“table.dataTable thead .sorting”的 css 时,标题的所有 td 都发生了变化,而不仅仅是它的文本。并且文本没有正确放置:(
    猜你喜欢
    • 2014-12-03
    • 2015-03-22
    • 1970-01-01
    • 2021-09-12
    • 1970-01-01
    • 2020-05-24
    • 2017-04-13
    • 1970-01-01
    • 2018-11-27
    相关资源
    最近更新 更多