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

在columndef datatable jquery中使用响应数据

  •  1
  • GauravSolo  · 技术社区  · 3 年前

    我使用的是datatable jquery。我想在td标签的数据id中使用Sr_no,但如何获取Sr_no的数据。

    或者你可以说我需要数据响应中的特定数据

    我在代码中突出显示了

    $("#fir").dataTable({
        "bProcessing": true,
    
        "sAjaxSource": "paid.php",
        "sDom": "<'row'<'col-sm-6'l><'col-sm-6'f>r>t<'row'<'col-sm-6'i><'col-sm-6'p>>",
        "sPaginationType": "full_numbers",
        "aoColumns": [
    
            {"mData": "Sr_no"}, <------ I dont want to add this column in table but I want to use value
            {"mData": "Category_Name"},
            {"mData": "Vendor_Name"},
            {"mData": "date"},
            {"mData": "Price"},
            {"mData": "Payment_Mode"},
            {"mData": "remark"},
            {"mData": "edit"},
            {"mData": "cancel"}
        ],
        'columnDefs': [
            {
               'targets': 1,
               'createdCell':  function (td, cellData, rowData, row, col) {
                   console.log(row,col);
                  $(td).attr('data-id',Sr_no);  <----------------
               }
            }
    
         ]
    
    });
    
    
    
    
    1 回复  |  直到 3 年前
        1
  •  2
  •   ruleboy21 Mohamad Shabihi    3 年前

    你可以用 rowData.Sr_no 获得价值 Sr_no 每行。改变 targets: 1

    {
       'targets': 1,
       'createdCell':  function (td, cellData, rowData, row, col) {
           console.log(row,col);
          $(td).attr('data-id', rowData.Sr_no);
       }
    }