Click here to Skip to main content
15,911,890 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
$.ajax({
    url: 'JQGridHandler.ashx',
    type: 'GET',
//    "stateSave": true,
//    "lengthMenu": [[10, 20, 50, -1], [10, 20, 50, "All"]],
    dataType: 'json',
    success: function (rows) {
        assignToEventsColumns(rows);
    }
});
function assignToEventsColumns(rows) {
    var table = $('#example').dataTable({
        "dom": 'C<"clear">lfrtip',
        "AutoWidth": true,
        "data": rows,
        "columns": [
                { "data": "Estimate_ID", "orderable": true },
                { "data": "ESTIMATE_DESCRIPTION", "orderable": false },
                { "data": "FLIGHT_START_DATE", "orderable": true },
                 { "data": "FLIGHT_END_DATE", "orderable": true },
                { "data": "ESTIMATE_COMMENTS", "orderable": false },
                { "data": "AGENCY_ID", "orderable": true },
                 { "data": "UPD_DATE", "orderable": true },
                { "data": "PROC_DATE", "orderable": false },
                { "data": "ESTIMATE_CD", "orderable": true },
                 { "data": "SALES_ASSISTANT", "orderable": true },
                { "data": "AE_STAFF_ID", "orderable": false },
                { "data": "order_type_id", "orderable": true },
                { "data": "cost_type", "orderable": true }
            ],
        "order": [[0, "asc"]]

//       "aoColumnDefs": [
//       {
//           "aTargets": [0],
//           "bSearchable": false,
//           "bSortable": false,
//           "bSort": false,
//           "mData": "Estimate_ID",
//           "mRender": function (event) {
//               return '<input class="childCheck" type="checkbox" id="childCheckBoxes" value="' + event + '">';
//           }
//       },
//       { "aTargets": [1], "mData": "ESTIMATE_DESCRIPTION" },
//       { "aTargets": [2], "mData": "FLIGHT_START_DATE" },
//       { "aTargets": [3], "mData": "FLIGHT_END_DATE" },
//       { "aTargets": [4], "mData": "ESTIMATE_COMMENTS" },
//       { "aTargets": [5], "mData": "AGENCY_ID" },
//       { "aTargets": [6], "mData": "UPD_DATE" },
//       { "aTargets": [7], "mData": "PROC_DATE" },
//       { "aTargets": [8], "mData": "ESTIMATE_CD" },
//       { "aTargets": [9], "mData": "SALES_ASSISTANT" },
//       { "aTargets": [10], "mData": "AE_STAFF_ID" },
//       { "aTargets": [11], "mData": "order_type_id" },
//       { "aTargets": [12], "mData": "cost_type" }
//       ]
    });
}
Posted

1 solution

A basic DataTable needs at least this:

HTML
<script>		
$(document).ready(function() {
    $('#example').DataTable( {
        "ajax":{
		"url":"URL HERE",
		"cache": true,
		"dataSrc": "People",}, // eg. DataSource
		"searching":false, // Optional
		"paging":false,
		"aaSorting": [[1,'desc'], [2,'asc']], // Optional
		"responsive":true, // Optional
		"bAutoWidth":false, // Optional
        "orderable": true, // Part 1 - Always true.
	columns: [
        { data: "DATA","width": "20%"}, // ID
        { data: "Name" },	// eg. Name column in DataSource
        { data: "Address" },    // eg. Address column in DataSource
        { data: "DATA", "orderable": false }, // Part 2 - False when we need it.
        { data: "DATA" }, // DateOfBirth
		{ data: "DATA" },
        { data: "DATA" },
		{ data: "DATA" },
		{ data: "DATA" },
	    {data:  "DATA"}
    ]
	});});
</script>



You have no DataSource

And regarding that commented out section, You don't need to use mData there because aTargets already resolved that.


Take note of what i did with "orderable"



Updated to give op some clarity:


HTML
<script>		
$(document).ready(function() {
    $('#example').DataTable( {
        "ajax":{
		"url":"URL HERE",
		"cache": true,
		"dataSrc": "DATASOURCE",}, // eg. WHATEVER YOUR DATASOURCE IS
		"searching":false, // Optional
		"paging":false,
		"aaSorting": [[1,'desc'], [2,'asc']], // Optional
		"responsive":true, // Optional
		"bAutoWidth":false, // Optional
        "orderable": true, // Part 1 - Always true.
	 "columns": [
                { "data": "Estimate_ID" },
                { "data": "ESTIMATE_DESCRIPTION", "orderable": false },
                { "data": "FLIGHT_START_DATE" },
                 { "data": "FLIGHT_END_DATE" },
                { "data": "ESTIMATE_COMMENTS", "orderable": false },
                { "data": "AGENCY_ID"},
                 { "data": "UPD_DATE"},
                { "data": "PROC_DATE", "orderable": false },
                { "data": "ESTIMATE_CD"},
                 { "data": "SALES_ASSISTANT"},
                { "data": "AE_STAFF_ID", "orderable": false },
                { "data": "order_type_id"},
                { "data": "cost_type"}
            ]
	});});
</script>
 
Share this answer
 
v11
Comments
Member 10902837 7-Dec-15 2:48am    
{data: "DATA"} in the DATA position should give my column names
Member 10902837 7-Dec-15 2:56am    
Uncaught TypeError: Cannot read property 'length' of undefined
getting this error
[no name] 7-Dec-15 3:03am    
I updated my answer, You still need to specify your DataSource.
Member 10902837 7-Dec-15 3:09am    
im getting an unknown parameter error for Estimate_id and it displays all null values in the tables
Member 10902837 7-Dec-15 3:29am    
getting error for the Estimate_id row 0 column 0

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