1

I am using the plugin "DataTables" and I'm wanting to add an image by line, that when the user clicks, call another url.

I followed the examples of www.datatables.net but is giving the below error:

DataTables warning (table id = 'myDataTable'): Requested unknown parameter '4' from the data source for row 0.

Records are shown on the screen

<h2>Index</h2>

<script type="text/javascript">
    $(document).ready(function () {

        var oTable = $('#myDataTable').dataTable({
            "bServerSide": true,
            "sAjaxSource": "AjaxHandler",
            "bProcessing": true,
            "sPaginationType": "full_numbers",   
            "aoColumns": [
                        { "mDataProp": "ID", "bSortable": false },
                        { "mDataProp": "Nome", "sTitle": "Identificação do produto" },
                        { "mDataProp": "Address", "sTitle": "Descrição do produto" },
                        { "mDataProp": "Town" },
                        { "fnRender": function (o) {return '<a href=/Produto/Detalhar/' + o.aData[0] + '>' + 'More' + '</a>';}} 
            ],
        });
    });
</script>


<table id="myDataTable" class="display">
    <thead>
        <tr>
            <th>ID</th>
            <th>Company name</th>
            <th>Address</th>
            <th>Town</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody> 
    </tbody>
</table>

2 Answers 2

5

I'm using dataTables version 1.10.0-dev and the accepted solution does not work for me, because o.aData is undefined. Instead I have all the properties of the json objects that I'm returning server side in o. So this is my solution:

$(document).ready(function () {
    var oTable = $('#myDataTable').dataTable({
        "bServerSide": true,
        "sAjaxSource": "AjaxHandler",
        "bProcessing": true,
        "sPaginationType": "full_numbers",
        "aoColumns": [
            { "mData": "ID", "bSortable": false },
            { "mData": "Nome", "sTitle": "Identificação do produto" },
            { "mData": "Address", "sTitle": "Descrição do produto" },
            { "mData": "Town" },
            {
                "mData": null,
                "bSortable": false,
                "mRender": function (o) { return '<a href=/Produto/Detalhar/' + o.Id + '>' + 'More' + '</a>'; }
            }
        ]
    });
});

I don't know if this depends on the new version of dataTables or from others configurations (but my table is configured in the same manner ...).

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, this code is work this url flexgestor.com.br/CA, and dataTable version is 1.9.4 @Daniele Armanasco
4

I don't really know datatable (not enough), but you should try this way: {not sure mDataProp is deprecated or not}

$(document).ready(function () {

        var oTable = $('#myDataTable').dataTable({
            "bServerSide": true,
            "sAjaxSource": "AjaxHandler",
            "bProcessing": true,
            "sPaginationType": "full_numbers",   
            "aoColumns": [
                        { "mData": "ID", "bSortable": false },
                        { "mData": "Nome", "sTitle": "Identificação do produto" },
                        { "mData": "Address", "sTitle": "Descrição do produto" },
                        { "mData": "Town" },
                        {   "mData": null,
                    "bSortable": false,
            "mRender": function (o) {return '<a href=/Produto/Detalhar/' + o.aData[0] + '>' + 'More' + '</a>';}
            }   
            ]
        });
    });

Be sure your data feet with you column declaration, you should have as ajax response a json with datas ID, Nome, Address and Town. If your first data is id not ID, you would get an error i think.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.