Click here to Skip to main content
15,909,953 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How could i display a new row in a datatable for every item in the array
Here is my code i get the eror DataTable not supported?

C#
var res = "";

    var arrayLength = resultArr.length;
    for (var i = 0; i < arrayLength; i++) {


        var t = $('#result').DataTable();
        var counter = 0;

        $('#result').on('click', function () {
            t.row.add([counter
            ]).draw();

            counter++;
        });

        $('#result').DataTable(resultArr[i].label);



Here is my table

HTML
<table id="result">
      <thead>
          <tr>
              <th>Title</th>
          </tr>
      </thead>

       </table>
Posted

1 solution

you need to add reference the datatables js and css files, for example
HTML
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
// JQuery Reference, If you have added jQuery reference in your master page then ignore, 
// else include this too with the below reference

<script src="https://cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.4/css/jquery.dataTables.min.css">


refer below article:
jQuery Datatables For Beginners[^]
 
Share this answer
 
Comments
Kurac1 13-Jan-15 10:07am    
Alright but my items still gets displayed at same line as it was one line

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900