Server side datatable data ajax data load problem....

Server side datatable data ajax data load problem....

evobyteevobyte Posts: 8Questions: 7Answers: 0
edited November 2022 in General

I have a table with a lots of data in my live server database. In that case if I load the total data at a time it get 12-15 seconds which is awkward. So I need to load the table server side. I have done it via ssp.class.php . It going fine when I load the table as normal structure like below:

array( 'db' => 'tel1', 'dt' => 13 ),
array(
'db' => 'is_active',
'dt' => 11,
'formatter' => function( $d, $row) {
if($d==0){
$tr_color='no';
}else{
$tr_color='yes';
}
return $tr_color;
}
);

But I need to access a array which is define outside formatter function. I have tried to access it as global variable but it is not available formatter function. Also it is not passed as parameter. So how can I access outside variable inside formatter function:
I have tried like below

array(
'db' => 'genere',
'dt' => 4,
'formatter' => function( $d, $row ) {
global $lang;
$gender = '';
if($d=='M'){
$gender = $lang['maschio'];
}else if($d=='F'){
$gender = $lang['femmina'];
}else if($d=='A'){
$gender = $lang['azienda'];
}
return $gender;
}

OR

array(
'db' => 'genere',
'dt' => 4,
'formatter' => function( $d, $row, $lang ) {
$gender = '';
if($d=='M'){
$gender = $lang['maschio'];
}else if($d=='F'){
$gender = $lang['femmina'];
}else if($d=='A'){
$gender = $lang['azienda'];
}

return $gender;
}

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,055 Site admin
     function( $d, $row ) use ( $lang ) {
    

    is what you want. This is part of how anonymous functions work in PHP.

    Allan

Sign In or Register to comment.