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

后端 未结 6 1904
深忆病人
深忆病人 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:13

    Below, is what I did to get altered html text in column cell, given a certain value in the aaData object array. This works, but feels horrible because html markup is in the javascript as above.

    var dataTableMeta = { "bProcessing": true,
                "bServerSide": true,
                "sAjaxSource": url
                                    , "aoColumns": aoColumns
                                    , "fnServerData": function (sSource, aoData, fnCallback) {
                                        $.ajax({ "dataType": 'json', "type": "POST", "url": sSource, "data": aoData, "success": fnCallback,
                                            'dataFilter': function (data, type) {
                                                var jsObject = jQuery.parseJSON(data);
                                                for (var i = 0; i < jsObject.aaData.length; i++) {
                                                    jsObject.aaData[i].CaseID = '' + jsObject.aaData[i].CaseID + '';
                                                }
                                                var jsonString = JSON.stringify(jsObject);
                                                return jsonString;
                                            }
                                        });
                                    }
            };
    
            $('#caseSearchTable').dataTable(dataTableMeta);
    

提交回复
热议问题