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

Custom Order on Server-Side

$
0
0
Hi!, first at all thanks a lot for this great plugin.
I'm having problems to understand how to change the order of columns on server-side.
I have readed this: http://datatables.net/examples/server_side/column_ordering.html but i just cant do it...
This is my script:
var oTable =$('#lista').dataTable( {
		"bProcessing": true, 
		"iDisplayLength": 10, 
		"sDom": '<"top">rt<"paginas"p><"clear"><"hidden"f>', 
		"sPaginationType": "full_numbers",
		"bServerSide": true, 
		"aaSorting": [[ 1, "desc" ]], 
		"sAjaxSource": "/Sources/table.php",
		"aoColumnsDefs": [
			{ "mData": "name", "aTargets": [0]},
			{ "mData": "promedio", "aTargets": [1] },
			{ "mData": "pais", "aTargets": [2] },
			{ "mData": "tipo", "aTargets": [3] }
		                		],
		
       	"fnServerData" : function ( sSource, aoData, fnCallback ) {
          aoData.push( 
		  				{ "name": "id_cat", "value": "<?php echo $idcat?>" },
						{ "name": "dato1", "value": $('#dato1').is(":checked") },
						{ "name": "dato2", "value": $('#dato2').is(":checked") },
						{ "name": "tipo1", "value": $('#tipo1').is(":checked") },
						{ "name": "tipo2", "value": $('#tipo2').is(":checked") },
		  				{ "name": "habilitado", "value": 1 }
					 ); 
          // send request to server, use default fnCallback to process returned JSON
          $.ajax( {
            "dataType": 'json',
            "url": sSource,
            "data": aoData,
            "success": fnCallback
          } );

And "table.php" :

$output = array(
		"sEcho" => intval($_GET['sEcho']),
		"iTotalRecords" => $iTotal,
		"iTotalDisplayRecords" => $iFilteredTotal,
		"aaData" => array()
	);
	while ( $aRow = mysql_fetch_array( $rResult ) )
	{
		$row = array();
		for ( $i=0 ; $i<count($aColumns) ; $i++ )
		{
			if ( $aColumns[$i] == "version" )
			{
				/* Special output formatting for 'version' column */
				$row[] = ($aRow[ $aColumns[$i] ]=="0") ? '-' : $aRow[ $aColumns[$i] ];
			}
			else if ( $aColumns[$i] != ' ' )
			{
				/* General output */
				$row[] = $aRow[ $aColumns[$i] ];
			}
		}
		$output['aaData'][] = $row;
				
	}

My json is returning this:

aaData: [[Ayres Village Apart, 4.42, 5, Argentina], [San Remo, 4.30, 5, Argentina],…]
0: [name1, 4.42, 5, location1]
0: "name1"
1: "4.42"
2: "5"
3: "location1"
1: [name2, 4.30, 5, location2]
0: "name2"
1: "4.30"
2: "5"
3: "location2"

where should i set the column order?
Thanks!

Viewing all articles
Browse latest Browse all 82039

Trending Articles