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

Wrong ordering script in server-side processing example

$
0
0
Hi everyone!

First of all, nice work!

I found a mistake in the examples section for server_side processing. The ordering algorithm does not work properly (tested with Version 1.9.4)

The old code
if ( isset( $_GET['iSortCol_0'] ) )
	{
		$sOrder = "ORDER BY  ";
		for ( $i=0 ; $i<intval( $_GET['iSortingCols'] ) ; $i++ )
		{
			if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" )
			{
				$sOrder .= $aColumns[ intval( $_GET['iSortCol_'.$i] ) ]."
				 	".mysql_real_escape_string( $_GET['sSortDir_'.$i] ) .", ";
			}
		}
		
		$sOrder = substr_replace( $sOrder, "", -2 );
		if ( $sOrder == "ORDER BY" )
		{
			$sOrder = "";
		}
	}

in my opinion it should look like
if (isset($_GET['iSortCol_0']))
	{
		if ($_GET['bSortable_'.intval($_GET['iSortCol_0'])] == "true")
		{
			$sOrder = "ORDER BY  ";
			$sOrder .= $aColumns[ intval( $_GET['iSortCol_0'] ) ]."
				 	".mysql_real_escape_string( $_GET['sSortDir_0'] ) .", ";
		}
	}


$_GET['iSortCol_0'] gives me the column number to sort
$_GET['bSortable_XY'] if the column can be sorted
$_GET['iSortCol_XY'] does not exist in the request (tested with google chrome developer tools)

In this way, sorting works fine in my application.

Greetings,
Alex

Viewing all articles
Browse latest Browse all 82115

Trending Articles



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