Skip to content

Instantly share code, notes, and snippets.

@rafiahmedd
Created August 4, 2021 22:52
Show Gist options
  • Save rafiahmedd/a091d4644c1be5f7cfbac9921a7c408e to your computer and use it in GitHub Desktop.
Save rafiahmedd/a091d4644c1be5f7cfbac9921a7c408e to your computer and use it in GitHub Desktop.
Add Serial number to targeted table
add_filter('ninja_table_rendering_table_vars',function($table_vars, $table_id, $tableArray){
$target_id = [2607,2608];
$tableId = 0;
foreach($target_id as $id){
if($table_id == $id){
$tableId = $id;
}
}
if($tableArray['table_id'] != $tableId) { return $table_vars; }
$counter_column = [
'name' => 'serial',
'key' => 'serial',
'title' => 'Serial',
];
array_unshift($table_vars['columns'], $counter_column);
return $table_vars;
},10,3);
add_action('ninja_tables_get_public_data',function($formatted_data, $ID){
$i = 1;
foreach($formatted_data as $key=>$value){
$formatted_data[$key]['serial'] = $i++;
}
return $formatted_data;
},10,2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment