Skip to content

Instantly share code, notes, and snippets.

@techjewel
Created October 18, 2018 12:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techjewel/9da3af0dd1f7fdee87e7576682a3bde8 to your computer and use it in GitHub Desktop.
Save techjewel/9da3af0dd1f7fdee87e7576682a3bde8 to your computer and use it in GitHub Desktop.
<?php
/*
* Say you have table which table id is 101 and you want to filter some data
* Please disable caching for this table and load using ajax renderer
*/
add_filter('ninja_tables_get_public_data', function ($data, $tableId) {
if($tableId != 101) {
return $data; // Return if this is not our target table
}
$modifiedData = array();
foreach ($data as $item) {
// say you have a column key as 'item_date' and you want to check the date if valid or not
if(isset($item['item_date']) & ninjaCustomIsValidDate($item['item_date'])) {
$modifiedData[] = $item;
}
}
return $data;
});
function ninjaCustomIsValidDate($date) {
// calculate and return true / false
return true;
}
@samjco
Copy link

samjco commented Jul 31, 2019

Can I use this to modify my table data in any other ways?

@mobtaker61
Copy link

hi
i want to filter my table by JS
but when add this code show error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment