Server-side and adding number record

Server-side and adding number record

ackzellackzell Posts: 7Questions: 0Answers: 0
edited June 2011 in General
Hi there,

I am using datatables 1.7.6, and server-side data from a php4 installation.

I want to add a row number fixed column as in the counter_column.html example BUT I am getting a little upset cause' I've been here for hours trying and I just cant fix it..

This setup is what "kind of" works for me:

PHP SCRIPT: (I'm guessing this would be enough...)

[code]
----------
$aColumns = array('users.payrollNumber', 'users.username', 'users.firstname', 'users.lastname','users.active', 'categorias.nombre', 'users.extension', 'roles.description' );

$sColumns = '"payroll,username,firstname,lastname,active,category,extension,role"';

/* Indexed column (used for fast and accurate table cardinality) */
$sIndexColumn = "users.payrollNumber";

/* DB table to use */
$sTable = "users";

$sTable .= " LEFT JOIN categorias ON users.categoriaid = categorias.id LEFT JOIN roles ON users.roleid = roles.roleid";

-------
/*
* Output
*/
$sOutput = '{';
$sOutput .= '"sEcho": '.intval($_GET['sEcho']).', ';
$sOutput .= '"sColumns": '.$sColumns.', ';
$sOutput .= '"iTotalRecords": '.$iTotal.', ';
$sOutput .= '"iTotalDisplayRecords": '.$iFilteredTotal.', ';
$sOutput .= '"aaData": [ ';

$totalColumns = count($aColumns);

//echo "columnas: " . $totalColumns;

while ( $aRow = mysql_fetch_row( $rResult ) )
{
for ( $i=0 ; $i < $totalColumns ; $i++ )
{

if ( $aColumns[$i] != ' ' )
{
/* General output */
$sOutput .= '"'.str_replace(
array( '"', "\n", "\r" ),
array( '\\"', "\\n", "\\n"),
$aRow[ $i ] ).'",';
}
}
/*
* Optional Configuration:
* If you need to add any extra columns (add/edit/delete etc) to the table, that aren't in the
* database - you can do it here
*/
$sOutput = substr_replace( $sOutput, "", -1 );

$sOutput .= "],";
}
$sOutput = substr_replace( $sOutput, "", -1 );
$sOutput .= '] }';

echo utf8_encode($sOutput);

?>
[/code]

and my datatables initialisation:
[code]

oTable = $('#data_tables').dataTable( {

"fnDrawCallback": function(oSettings){
//cambio de color con el mouse encima
$('#data_tables tr').hover(
function()
{
$(this).children('td').each(function ()
{
if($(this).hasClass('sorting_1'))
$(this).addClass('highlightSort');
else
$(this).addClass('highlight');
});
},
function()
{
$(this).children('td').removeClass('highlight');
$(this).children('td').removeClass('highlightSort');
}
);

if ( oSettings.bSorted || oSettings.bFiltered )
{
for ( var i=0, iLen=oSettings.aiDisplay.length ; i

Replies

  • ackzellackzell Posts: 7Questions: 0Answers: 0
    still haven't figured out... any ideas?
    thanks!
  • numberonenumberone Posts: 86Questions: 0Answers: 0
    edited July 2011
    dunno about js part much but you can try if the problem is 'payroll':
    [code]
    $aColumns = array('users.payrollNumber as payroll', 'users.payrollNumber as payroll_column2', 'users.username', 'users.firstname', 'users.lastname','users.active', 'categorias.nombre', 'users.extension', 'roles.description' );

    $sColumns = '"payroll,payroll_column2,username,firstname,lastname,active,category,extension,role"';
    [/code]
  • ackzellackzell Posts: 7Questions: 0Answers: 0
    hi numberone!

    thanks for replying

    I removed the condition [code] if ( oSettings.bSorted || oSettings.bFiltered ) [/code]

    and it works now.... I still don't really know what it is, but at least it does the job. :)
This discussion has been closed.