Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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>
share|improve this question

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.