【问题标题】:Trying to display custom value in cell using mRender returns an error using Datatables尝试使用 mRender 在单元格中显示自定义值使用 Datatables 返回错误
【发布时间】:2015-03-27 12:23:57
【问题描述】:

我在 angularjs 中使用数据表在表格中显示产品列表。 通过使用 mData 我可以将值绑定到列,但是在尝试使用 mRender 时它返回错误。

      <table ui-jq="dataTable" ui-options="{
      sAjaxSource: 'http://www.server.netshell:3001/product/getMyProductsList', 
      aoColumns: [
        { mData: null,sDefaultContent: '' },
        { mData: 'productname' },
        { mData: 'published' },
        { mData: 'condition' },
        { mData: 'type' },
        { mData: 'category' },
        { mData: 'price'},
        { mData: null, sDefaultContent: ''},
        { mRender: function(data, type, val){
            return data.productID;
        }}

      ]
    }" class="table table-striped b-t b-b" id="pTable">
    <thead>
      <tr>
        <th  style="width:20%">Product ID</th>
        <th  style="width:20%">Product Name</th>
        <th  style="width:25%">Status</th>
        <th  style="width:25%">Condition</th>
        <th  style="width:15%">Type</th>
        <th  style="width:15%">Category</th>
        <th  style="width:15%">Price</th>
        <th  style="width:15%">Added</th>
        <th  style="width:15%">Action</th>
      </tr>
    </thead>
    <tbody>
    </tbody>
  </table>

在这里,我正在尝试获取 ProductId 并将该 ID 发送到我的控制器以进行 EditDelete onclick。但是当尝试在该列中显示简单的 productId 时,它返回了一个错误

看起来像语法错误,但找不到我错过的地方!

有人可以帮我解决这个问题吗? 参考Datatables mData

【问题讨论】:

    标签: jquery angularjs datatables jquery-datatables


    【解决方案1】:
    1. 您得到的错误来自 AngularJS 解析 ui-options 属性。我不确定,但 mRender 之后的双 } 可能有问题,请尝试在此处插入空格或换行符。
    2. 根据您给出的参考,mRender 在同一列中需要对应的mDatadata 参数是您提供的 mDataval 参数是行的完整对象。也检查一下。

    【讨论】:

      猜你喜欢
      • 2015-02-02
      • 1970-01-01
      • 2015-09-20
      • 2019-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多