Datatables simple reference

Specify display column (default with sorting capability):

"aoColumns" : [
	{
	   "sTitle" : "Agency Code",
	   "mData" : "agencyCode"
	},
	{
	   "sTitle" : "Agency Name",
	   "mData" : "agencyName"
	}
],

To disabled column sorting

"aoColumns" : [
	{
	   "sTitle" : "Agency Code",
	   "mData" : "agencyCode",
           "bSortable: : false 
	},
	{
	   "sTitle" : "Agency Name",
	   "mData" : "agencyName"
	}
],

Specific columns with custom link

"aoColumns" : [
 {
    "sTitle" : "Agency Code",
    "mData" : "agencyCode",
    "fnRender" : function(obj) {
	 return "<a href=agencies/" + obj.aData.agencyCode + ">" + obj.aData.agencyCode + "</a>";
       } 
 },
 {
    "sTitle" : "Agency Name",
    "mData" : "agencyName"
  }
],

 

Update 2018

Use columnDefs, set for target columns and set order able to false.

var dt = $('#dataTable').DataTable({
            "keys": true,
            "processing": true,
            "serverSide": true,
            "searching" : false,
            "pageLength" : 10,
            "lengthChange" : false,
            "ajax": {
                "url": "{{ url_for('merchant.filter') }}",
                "type": "POST",
                "data": function( d ) {
                    d.search = $("#sSearch_0").val(), //name or description 
                    d.category = $("#category").val()   //category
                    d.status = $("#status").val()   //latitude   
                },
                // "dataSrc": 'data'
            },
            "columns" : [
                { "data" : "merchant_code" },
                { "data" : "merchant_name" },
                { "data" : "merchant_type" },
                { "data" : "expired_date" },
                { "data" : "status" },
                { "data" : "is_active" },
            ],
            "columnDefs": [
                {
                    targets: [ 2, 3, 4, 5 ], //or use "_all"
                    orderable: false
                },
            ],
            "pagingType" : "numbers",
            "autoWidth"  : true,
            "autoFill"   : true,
            "order": [[1, "desc"]]
        });

 

Datatables simple reference

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.