1

我有很多列表页面,只有一个用于配置所有数据表设置的 js 文件。为此,我将 aoColumns 的值从每个列表页面发送到写入数据表逻辑的公共 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'
});

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

提前致谢。

4

0 回答 0