Javascript Datatable限制单元格中显示的字符数 [英] Javascript Datatable limit amount of characters shown in a cell

查看:15
本文介绍了Javascript Datatable限制单元格中显示的字符数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 Javascript 创建一个 DataTable,它具有以下属性:

I am creating a DataTable in Javascript, which has the following properties:

var dtable = $('.ssdatatable').DataTable({
    "lengthMenu": [[10, 25, 50, 100, 500], [10, 25, 50, 100, 500]],
    "bProcessing": true,
    "sDom": "TBflrtip",
    "bServerSide": true,
    "sAjaxSource": ajSource,
    "iDisplayLength": 25,
    "bJqueryUI": false,
    "bAutoWidth": false,
    //"bAutoLength": false,
    //"bLengthChange": false,
    "recordsFiltered": 0,
    "sPaginationType": "full_numbers",
    "bPaginate": true,
    "sServerMethod": "POST",
    "responsive": true,
    "fixedHeader": true,
    "buttons": [
            'copy', 'excel', 'pdf'
    ],
    "aoColumns": [
        //columns
    ]
});

其中一列是描述,其中包含大量文本.列的宽度是固定的,但正因为如此,我的行的高度不成比例,使页面 x10 达到其预期大小.

One of the particular columns is a Description, which has a LOT of text in it. The width of columns is fixed, however because of that, the height of my rows are blowing out of proportions, making page x10 of its intended size.

我的问题是:是否可以在属性中添加任何内容以使其仅显示 N 个字符,并且通过达到限制,它将类似于:

|text textte...|
|     Show More|      

(我尝试注释掉选项,对我有好处)

(I tried commented out options, did do me any good)

或者我需要使用某种方法或修改css吗?

Or would I need to use some method or modify css?

推荐答案

给定数据:

var mydt = [{ a: 1, b: 2, c: 3, d: 4 }, { a: 5, b: 6, c: 7, d: 8 }, { a: 10, b: 12, c: 13, d: 14 }];


                    $("#tbl2").DataTable({
                        columnDefs: [{ targets:[0] }],
                        data: mydt, columns: [{ data: "a" }, { data: "b" }, { data: "c" }, { data: "d" }],
                        createdRow: function (row, data, c, d) {

                         // so for each row, I am pulling out the 2nd td
                         // and adding a title attribute from the 
                        // data object associated with the row.


                            $(row).children(":nth-child(2)").attr("title", data.b)


                        },



                  and the rest

这是 jfiddle 中的一个工作 https://jsfiddle.net/bindrid/wbpn7z57/7/ 请注意,这个数据格式不同,但它有效(在名字列上)

here is a working one in jfiddle https://jsfiddle.net/bindrid/wbpn7z57/7/ note that this one has data in a different format but it works (on the first name column)

这篇关于Javascript Datatable限制单元格中显示的字符数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆