代码之家  ›  专栏  ›  技术社区  ›  fips123

数据表:更改日期格式

  •  0
  • fips123  · 技术社区  · 10 年前


    我的JS:

    $(function() {
    $("#mytable").dataTable({
        processing: true,
        serverSide: true,
        ajax: {
            "url": JS_BASE_URL + "work/dataTable",
            "type": "POST"
        },
        columns: [
            { data: "customer_name" },
            { data: "work_date" }, 
            { data: "work_time"},
            { data: "work_text"},
        ],
        columnDefs:     {   
            type: 'de_date', targets: 1 }
    }).dataTableSearch(500); });
    

    数据输入 work_date 格式为:2015-08-09
    我想把它改为:2015年8月9日。
    date-de.js 加载,columnsDefs配置为写入datatables.net。

    它没有改变日期的格式,我仍然得到2015-08-09。我使用Codeigniter 3会有问题吗?

    1 回复  |  直到 10 年前
        1
  •  1
  •   Gyrocode.com    10 年前

    你可以使用 columnDefs 选项,其中 targets 是从零开始的列编号:

    this_table = $('#lancers_grid').dataTable({
    // ...
    columnDefs : [
        {
        targets : 1,
            render : function(this_date){
                //Here you should call the date format function:
                return datejs_format_function(this_date);
            }
        }]
    // ...
    });
    
    推荐文章