简体   繁体   中英

Using fnRender with ajax source datatable

I was trying just modifying one of the examples to do customize a cell:

var oTable = $('#example').dataTable( {
                "bProcessing": true,
                "sAjaxSource": "sources/deep.txt",
                "aoColumns": [
                    { "mDataProp": "engine" },
                    { "fnRender": function( oObj ) {
                                    return "Test";
                                } },
                    { "mDataProp": "platform.inner" },
                    { "mDataProp": "platform.details.0" },
                    { "mDataProp": "platform.details.1" }
                ]
            } );

Which uses a source like:

{ "aaData": [
{
    "engine": "Trident",
    "browser": "Internet Explorer 4.0",
    "platform": {
        "inner": "Win 95+",
        "details": [
            "4",
            "X"
        ]
    }
},
...
...

Data is displayed correctly but I started getting "DataTables warning (table id = 'example'): Requested unknown parameter '1' from the data source for row 0"

Anything I'm missing? Or I should be doing this in a different way?

With help of official support I found the answer:

An additional parameter needs to be defined in order to avoid that alert:

{                "sDefaultContent": "",
                 "fnRender": function( oObj ) {
                               return "Test";
} }

http://datatables.net/forums/discussion/9030/using-fnrender-with-ajax-source-datatable#Item_1

Are you sure thatyour error isn't here

                { "mDataProp": "platform.details.0" },
                { "mDataProp": "platform.details.1" }

that should be

                { "mDataProp": "platform.details[0]" },
                { "mDataProp": "platform.details[1]" }

since details is an array?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM