9

I have the flat Json string produced by my aspx webpage..

[{"UserName":"ABENS"},{"UserName":"AILPAL"},{"UserName":"ANDREW.GUILLERMO"}.....(so on so forth)]

I have declared the following html..

            <table id="tblUserAccountsManagement" class="display" cellspacing="0">                    
                         <thead>
                            <tr>
                                <th>UserName</th>

                            </tr>
                        </thead>                                

                    </table>

I have the following Jquery...

  $(document).ready(function () {

        var tbl = $('#tblUserAccountsManagement').DataTable({

            "ajax": {

                "url": "AccountsManagementJSON.aspx",
                "dataSrc": ""

            },

            "columns": [

                { "data": 'UserName' }

            ],
            autofill: true,
            select: true,
            responsive: true,
            buttons: true,
            length: 10,

        });
    });

Why does it still output the error?

Requested unknown parameter '0' for row '0' column '0'

I've read everything followed every troubleshoot there is, made sure that html and jQuery definition are intact.. why doesn't it still work?

What I don't understand is that I've tried this before here and it worked. I only had to add dataSrc: "" and that did the trick. I followed my previous example to the letter and now it does not work.

What's weird is that it does show the number of rows (39 rows like in the JSON) But it won't show content. Why is that?

Malcolm Salvador
  • 1,476
  • 2
  • 21
  • 40
  • Can you supply an example of your JSON? May not be formatted right for datatables? – jonmrich Mar 01 '17 at 01:06
  • The example is included in the question. It is a flat array. I followed the guide here: https://datatables.net/examples/ajax/custom_data_flat.html – Malcolm Salvador Mar 01 '17 at 01:45
  • That's very odd, I've worked up a JSFiddle with your data (https://jsfiddle.net/annoyingmouse/da2vbL1L/) and everything seems to be working correctly. Just an idea, but your server isn't doing something odd like adding a BOM? Probably not but perhaps look at the response from your ajax and check? – annoyingmouse Mar 01 '17 at 07:38
  • @annoyingmouse thanks for taking concern sir. Actually I think maybe it's a quirk with asp webforms? I gotta get out of this platform. Wwe've actually resolved it here. https://datatables.net/forums/discussion/40914/persistent-error-requested-unknown-parameter-0-for-row-0-column-0#latest – Malcolm Salvador Mar 01 '17 at 09:24

1 Answers1

5

I have resolved the problem: I have used aoColumns and mData with this setup (Webforms with MasterPages).

the following now works :

 $(document).ready(function () {

    var tbl = $('#tblUserAccountsManagement').DataTable({

        "ajax": {

            "url": "AccountsManagementJSON.aspx",
            "dataSrc": ""

        },

        aoColumns: [

            { mData: 'UserName' }

        ],
        autofill: true,
        select: true,
        responsive: true,
        buttons: true,
        length: 10,

    });
});
Malcolm Salvador
  • 1,476
  • 2
  • 21
  • 40
  • 3
    Your example helped me figure out that I had my 'columns' structure in the wrong place -- i had it buried within the 'ajax' structure. i need to invest in an IDE. – Peter Smith May 01 '21 at 06:37
  • 1
    @PeterSmith glad I could help – Malcolm Salvador May 02 '21 at 19:26
  • 1
    @PeterSmith your comment on the example that helped you realized your structure was in the wrong place helped me realize my structure was in the wrong place. :) – Jim Apr 03 '23 at 19:27