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?

4
  • Can you supply an example of your JSON? May not be formatted right for datatables? Commented Mar 1, 2017 at 1:06
  • The example is included in the question. It is a flat array. I followed the guide here: datatables.net/examples/ajax/custom_data_flat.html Commented Mar 1, 2017 at 1:45
  • That's very odd, I've worked up a JSFiddle with your data (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? Commented Mar 1, 2017 at 7: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. datatables.net/forums/discussion/40914/… Commented Mar 1, 2017 at 9:24

1 Answer 1

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,

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

3 Comments

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.
@PeterSmith glad I could help
@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. :)

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.