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

如何在react bootstrap表的列定义中使用矩库?

  •  0
  • tesicg  · 技术社区  · 7 年前

    我的代码如下:

    const columns = [{
      dataField: 'Id',
      text: 'Order ID'
    }, {
      dataField: 'Date',
      text: 'Date'
    }, {
      dataField: 'Total',
      text: 'Total'
    }];
    

    它在react引导表中显示日期。但是,日期是json格式的,我不需要。

    我尝试使用矩库以这种方式格式化日期:

    const columns = [{
      dataField: 'Id',
      text: 'Order ID'
    }, {
      dataField: '{moment(Date).format("DD-MM-YYYY")}',
      text: 'Date'
    }, {
      dataField: 'Total',
      text: 'Total'
    }];
    

    但是,日期列是空的。

    如何使用矩库格式化react bootstrap表库中列的日期?还是有别的办法?

    2 回复  |  直到 7 年前
        1
  •  1
  •   AllenFang    7 年前

    column.formatter 可以帮助你。有一个在线演示: this

        2
  •  0
  •   Anupam Maurya    6 年前

    以下是rendor方法中的示例代码

    render () {
            let columns = []
            columns = [
             { name: 'createAt',
            displayName: 'my-Date',
            dataFormat: function callback (cell, row, rowIndex, colIndex) { moment(cell).format('DD.MM.YYYY h:mm') },
            hideFilter: true,
            isKey: true,
            width: '140'
        }]
    
    推荐文章