I want to create links in record fields in DataTables from JSON data

后端 未结 6 1912
深忆病人
深忆病人 2020-12-28 19:09

I\'m creating a dataTables table to use as an archive of pages for a site that produces a comic strip. On that archives page, I\'d like to have the title of the comic be a l

6条回答
  •  一个人的身影
    2020-12-28 19:37

    You could also use the mRender function with aoColumnDefs:

    $('#example').dataTable({
      "bProcessing": true,
      "bServerSide": true,
      "sAjaxSource": "archive/archive.txt",
      "aoColumnDefs": [            
         {
           "aTargets": [ 2 ], // Column to target
           "mRender": function ( data, type, full ) {
             // 'full' is the row's data object, and 'data' is this column's data
             // e.g. 'full[0]' is the comic id, and 'data' is the comic title
             return '' + data + '';
           }
         }
       ]
    });
    

    This is more explicit and likely more maintainable because you can specify how individual columns render at the column level, rather than selecting them through the DOM at the row level, which helps when you're adding columns later on.

提交回复
热议问题