datatables列宽问题

时间:2013-08-20 05:18:36

标签: jquery width jquery-datatables

我有很多列表页面,只有一个js文件用于配置所有数据表设置。为此,我将aoColumns的值从每个列表页面发送到写入datatables逻辑的公共js文件。 我在我的一个列表页面中写了一个函数,如:

public function assignedToMeHideSort()
{
    return array(
        "{bSortable: false}", "null", "null", "{bSortable: false}", "null",
        "null", "null", "null", "null", "null", "null", "null", "null", "null",
        "null", "null", "null", "null", "{\"bSortable\": false}"
    );
}

$aoColumn = assignedToMeHideSort();
echo '<input type="hidden" name="aoColumn" id="aoColumn" value="' . implode(",", $aoColumn) . '">';

然后在常见的js文件中我写了:

if ($('#aoColumn').val()) {
    var ao = [];
    var aos = $('#aoColumn').val().split(',');
    for (var i = 0; i < aos.length; i++) {
        if (aos[i] == 'null') {
            //no need for processing
            ao.push('{ null }');
        } else {
            //remove {, } and whitespace, return array splitted by :
            var s = aos[i].replace('{', '').replace('}', '').replace(' ', '').split(':');
            //create object
            var o = {};
            //here you need to force a real boolean instead of "false"
            o[s[0].toString()] = (s[1] == "false") ? false : true;
            ao.push(o);
        }
    }
}
var oTable = $('#data-table').dataTable({
    "sDom": 'CT<"clear">firtlip',
    "oTableTools": {
        "sSwfPath": basePath + "/js/extras/TableTools/media/swf/copy_csv_xls_pdf.swf",
        "aButtons": [
            {"sExtends": "csv", "sFileName": curpath + ".csv", "sButtonText": "Save to CSV", "mColumns": "visible"}
        ]
    },
    "aaSorting": [
        [0, "desc"]
    ],
    "bAutoWidth": false,
    "aLengthMenu": [
        [10, 25, 50, -1],
        [10, 25, 50, "All"]
    ],
    "iDisplayLength": 10,
    "oLanguage": {
        "sSearch": "Filter : "
    },
    "aoColumns": ao,
    'sPaginationType': 'full_numbers'
});

但是在列表页面中,所有列的宽度显示为100px。我想改变它,它会因列而异。为此,我在aoColumnDefs之后添加了aoColumns sWidth属性。但它不起作用。 请指导我如何解决这个宽度问题。

提前致谢。

0 个答案:

没有答案