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

DataTable refuses to populate

$
0
0

The below listed code is almost exactly out of the DataTables.Net documentation.

I make an Ajax call to the server, code below, and the table does Not Populate

HTML

    <table width="100%" id="example" cellspacing="0" class="display">
        <thead>
            <tr>
                <th>comp_name</th>
                <th>addr_Address1</th>
                <th>addr_State</th>
                <th>pers_FirstName</th>
                <th>pers_LastName</th>
                <th>pers_Gender</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Row 1 Data 1</td>
                <td>Row 1 Data 2</td>
            </tr>
            <tr>
                <td>Row 2 Data 1</td>
                <td>Row 2 Data 2</td>
            </tr>
        </tbody>
        <tfoot>
            <tr>
                <th>comp_name</th>
                <th>addr_Address1</th>
                <th>addr_State</th>
                <th>pers_FirstName</th>
                <th>pers_LastName</th>
                <th>pers_Gender</th>
            </tr>
        </tfoot>
    </table>

JavaScript code:

      var myTable = $('#example').DataTable( {
          ajax: { url: "/api/PatientData/SearchPatientRecord"
                   },
        columns: [
        { data: "comp_name" },
        { data: "addr_Address1" },
        { data: "addr_State" },
        { data: "pers_FirstName" },
        { data: "pers_LastName" },
        { data: "pers_Gender" }
        ]
       } );

server code:

public class PatientRecord
{
    public string comp_name { get; set; }
    public string addr_Address1 { get; set; }
    public string addr_State { get; set; }
    public string pers_FirstName { get; set; }
    public string pers_LastName { get; set; }
    public string pers_Gender { get; set; }

    public PatientRecord() { }

}


public class PatientRecordList
{
    public long draw { get; set; }
    public int recordsTotal { get; set; }
    public int recordsFiltered { get; set; }
    public PatientRecordList() { }
    public List<PatientRecord> data = new List<PatientRecord>();
}



        PatientRecord prcd = new PatientRecord();

        prcd.addr_Address1 = "1st street";
        prcd.addr_State = "NY";
        prcd.comp_name = "Trump";
        prcd.pers_FirstName = "Betty";
        prcd.pers_Gender = "F";
        prcd.pers_LastName = "Smith";


        PatientRecordList prcdLst = new PatientRecordList();

        prcdLst.data.Add(prcd);

        prcdLst.recordsTotal = 75;
        prcdLst.recordsFiltered = 0;
        //          prcdLst.draw = Convert.ToInt64(variables[2]);
        prcdLst.draw = 1;

        return JsonConvert.SerializeObject(prcdLst);

Viewing all articles
Browse latest Browse all 82778

Trending Articles



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