1

I tried to create table using datatable.js ajax. I'm getting data from webmethod , but, result is not adding into the tables.

JS Method

 function getMyData() {
            alert('d');
            $.ajax({
                type: "POST",
                url: "AssignHistory.aspx/getModemAssign ",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: buildMyDatatable,
                error:
                    function (msg) {
                        alert(msg.status + " " + msg.statusText);
                    }
            });

            function buildMyDatatable(result) { 
                var data = JSON.stringify(result.d);
                $('#gvAssgin').dataTable({
                    retrieve: true,
                    JSON:data,
                    columns: [
                            { data: "ModemId" },
                            { data: "ModemName" }
                    ]
                }); 
            }
        } 

HTML Code

   <table id="gvAssgin">
      <thead>
        <tr>
             <th>
                   Modem ID 
             </th>
             <th>
                   Modem Name 
             </th>
         </tr>
   </thead>                                 

Result I'm getting is, enter image description here

waiting for replies

1 Answer 1

1

Correct option of JavaScript sourced data is data. Also there is no need to generate JSON again with JSON.stringify(result.d), just pass the array to jQuery DataTables.

See the corrected code below:

$('#gvAssgin').dataTable({
    data: result.d,
    columns: [
       { data: "ModemId" },
       { data: "ModemName" }
    ]
}); 
Sign up to request clarification or add additional context in comments.

3 Comments

thanks it helps me.I have one more query, that i trying to create a check box inside the Datatable column and i need to set data value to that check box
@KarthikTv, regarding checkboxes, please see our article Row selection using checkboxes and Select extension and How to add a checkbox column
Thanks you so much. I have posted another one question similar to this. can you please Look into that. It will save my day. stackoverflow.com/questions/35219337/…

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.