Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82439

Ways of passing data to datatable

$
0
0

Hi everyone,

I have a jquery post like following, and which updates my existing datatable directly by injecting the data into the DOM like following:

  $.post("/SearchCompetitor/Index", { username: _username }, StartLoading())
                               .done(function (data) {
                                   if (data !== "UsernameError") {


                                       var dbtb = $('<table />').append(data).find('#datatable-responsive').html();
                                       $('#datatable-responsive').html(dbtb);

                                       $('#datatable-responsive').dataTable({

                                        "bDestroy": true
                                       });
                                    // This is where I re-create the table to display the data
                                   }
                                   else {
                                       StopLoading();
                                       ShowMessage("No user was found under: " + $('.txtSearch').val());
                                   }
                               })

The "data" object holds the HTML of the table and what I'm trying to figure out here is how to pass the data directly into the datatable, instead of directly injecting it into the DOM like I'm doing right now:

                                   var dbtb = $('<table />').append(data).find('#datatable-responsive').html();
                                   $('#datatable-responsive').html(dbtb);

So my questions are:

  1. How to convert a C# List into a DBTable JSon acceptable format
  2. How to fill the data directly into the dbtable,without first injecting it into the DOM of the browser

Can someone help me out with this please?


Viewing all articles
Browse latest Browse all 82439


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>