Last active
November 20, 2015 03:55
-
-
Save mgratch/2bb8608e05300c36bccd to your computer and use it in GitHub Desktop.
Attempting to override the data source for dataTables view to allow for multi-column sort. This should be view agnostic, allowing for these options to override any datatable view.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Plugin Name: GravityView - Edit DataTables Options | |
* Plugin URI: http://gravityview.co/extensions/datatables/ | |
* Description: This plugin is used to override the datatables data source and extend it. | |
* Version: 1.0 | |
* Author: Katz Web Services, Inc. , Marc Gratch | |
* Author URI: http://www.katzwebservices.com | |
* License: GPLv2 or later | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html | |
*/ | |
add_filter( 'gravityview_datatables_js_options', 'disable_gravityview_datatables_search', 10, 3 ); | |
/** | |
* Disable the DataTables search filter | |
* @param [type] $dt_config [description] | |
* @param [type] $view_id [description] | |
* @param [type] $post [description] | |
* @return [type] [description] | |
*/ | |
function disable_gravityview_datatables_search( $dt_config, $view_id, $post ) { | |
$array_to_encode = array(); | |
$col_id = array(); | |
$col_labels = array(); | |
$field_settings = array(); | |
$view_data = gravityview_get_current_view_data($view_id); | |
$return_config = $dt_config; | |
$columns = $return_config['columns']; | |
$entries = gravityview_get_entries($view_data['form_id']); | |
foreach ($columns as $temp_col){ | |
$field_id = substr($temp_col['name'],3); | |
$col_id[] = $field_id; | |
$col_labels[] = array( | |
'name' => gv_label($field_id), | |
'width' => null | |
); | |
} | |
$columns = $col_id; | |
foreach ($entries as $entry_a){ | |
$entry_data = array(); | |
foreach ($columns as $col){ | |
//$entry_data[] = gravityview_get_field_value($entry_a,$col,$display_value); | |
$field_settings['id'] = $col; | |
$entry_data[] = gv_value($entry_a,$field_settings); | |
} | |
$array_to_encode[] = $entry_data; | |
} | |
unset($return_config['ajax']); | |
$return_config['serverSide'] = false; | |
$return_config['searching'] = false; | |
$return_config['stateSave'] = false; | |
$return_config['processing'] = false; | |
$return_config['deferRender'] = false; | |
$return_config['retrieve'] = false; | |
$return_config['data'] = $array_to_encode; | |
$return_config['columns'] = $col_labels; | |
return $return_config; | |
} | |
add_filter( 'gravityview_search_criteria', 'my_gv_custom_role_filter', 110, 1 ); | |
function my_gv_custom_role_filter( $criteria ) { | |
$criteria['search_criteria']['status'] = 'active'; | |
$criteria['paging'] = array( 'offset' => 0, 'page_size' => 1000 ); | |
return $criteria; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment