Skip to content

Instantly share code, notes, and snippets.

@annuman97
Created May 7, 2024 11:27
Show Gist options
  • Save annuman97/c05e8d7bf763184d821e490e58e56986 to your computer and use it in GitHub Desktop.
Save annuman97/c05e8d7bf763184d821e490e58e56986 to your computer and use it in GitHub Desktop.
Auto Serial Number column to a Table in NT
// Auto serial number
add_filter('ninja_table_rendering_table_vars', function($table_vars, $table_id, $tableArray){
$target_id = 1320;
if ($tableArray['table_id'] != $target_id) {
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