Support

Home Forums Event Espresso Premium Sorting by custom column in Event's registration table

Sorting by custom column in Event's registration table

Posted: April 6, 2018 at 11:54 am


bhesketh

April 6, 2018 at 11:54 am

Hi

I’ve added custom column to Event Registrations admin table and now need to enable sorting of registrations by that column.

Is there a sorting filter for that?

Thank you for helping!


Tony

  • Support Staff

April 12, 2018 at 4:19 am

Hi there,

It turns out there is a filter for this:

$_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen);

To add sorting to a custom column named ‘custom_column’, you would do something like this:

function tw_ee_sortable_columns( $sortable_columns, $screen ) {
	if ( $screen == 'espresso_registrations_default' ) {
		$sortable_columns['custom_column'] = array('custom_column' => TRUE);
	}
	return $sortable_columns;
}
add_filter('FHEE_manage_event-espresso_page_espresso_registrations_sortable_columns', 'tw_ee_sortable_columns', 10, 2);


bhesketh

April 12, 2018 at 10:18 am

Thank you. The code kind of works, but the sorting doesn’t work right.

Is there still anything missing?


bhesketh

April 12, 2018 at 1:37 pm

I’m able to click on column heading, the URL shows proper information ASC and DESC by the proper field, but the sorting doesn’t work right.

function tw_ee_sortable_columns( $sortable_columns, $screen ) {
if ( $screen == ‘espresso_registrations_default’ ) {
$sortable_columns[‘myCustomColumnName’] = array(‘myCustomColumnName’ => TRUE);
}
return $sortable_columns;
}
add_filter(‘FHEE_manage_event-espresso_page_espresso_registrations_sortable_columns’, ‘tw_ee_sortable_columns’, 10, 2);


bhesketh

April 12, 2018 at 1:38 pm

here is the URL – /wp-admin/admin.php?page=espresso_registrations&orderby=myCustomColumnName&order=asc


Tony

  • Support Staff

April 12, 2018 at 2:10 pm

What values are in your custom column?


bhesketh

May 4, 2018 at 2:31 pm

Hi

This topic is to continue the older topic

https://eventespresso.com/topic/sorting-by-custom-column-in-events-registration-table/

For a custom column I use unique registration code. It’s a 3 digits random number.

add_filter(‘FHEE_manage_event-espresso_page_espresso_registrations_sortable_columns’, ‘tw_ee_sortable_columns’, 10, 2);

function tw_ee_sortable_columns( $sortable_columns, $screen ) {
if ( $screen == ‘espresso_registrations_default’ ) {
$sortable_columns[‘lottery_number’] = array(‘lottery_number’ => TRUE);
}
return $sortable_columns;
}


Tony

  • Support Staff

May 8, 2018 at 5:28 am

I’ve merged your new thread with your older one.

Ok, so when you say the sorting doesn’t work right, what happens when you sort using that field?


bhesketh

May 8, 2018 at 7:10 am

It looks like it sorts by registration date and time instead of my custom column


bhesketh

May 8, 2018 at 7:24 am

Here is var_dump of $sortable_columns

array(6) {
[“_REG_date”]=>
array(1) {
[“_REG_date”]=>
bool(true)
}
[“ATT_fname”]=>
array(1) {
[“ATT_lname”]=>
bool(false)
}
[“event_name”]=>
array(1) {
[“event_name”]=>
bool(false)
}
[“DTT_EVT_start”]=>
array(1) {
[“DTT_EVT_start”]=>
bool(false)
}
[“_REG_ID”]=>
array(1) {
[“_REG_ID”]=>
bool(false)
}
[“lottery_number”]=>
array(1) {
[“lottery_number”]=>
bool(true)
}
}


bhesketh

May 8, 2018 at 7:32 am

I renamed lottery_number to REG_code, because it was actually edited REG_code and it still saves in the database as REG_code.

The lottery_number field is REG_code field that I modified.

1. Here is how I changed the REG_code to make it random within a specific event

function change_reg_code($new_reg_code, $transaction, $ticket) {

global $wpdb;

if ( $ticket instanceof EE_Ticket ) {
$dtt = $ticket->last_datetime();
if ( $dtt instanceof EE_Datetime ) {
$event = $dtt->event();
if ( $event instanceof EE_Event ) {
$evt_id = $event->ID();
}
}
}
$sql = “SELECT REG_code “;
$sql .= “FROM {$wpdb->prefix}esp_registration “;
$sql .= “WHERE {$wpdb->prefix}esp_registration.EVT_ID = %d”;

$attendees = $wpdb->get_results( $wpdb->prepare( $sql, $evt_id ));

$new_reg_code = strval(rand(100, 999));
while(array_filter($attendees, function ($e) use ($new_reg_code) {return $e->REG_code == $new_reg_code;}))
{
$new_reg_code = strval(rand(100, 999));
}

return $new_reg_code;
}
add_filter(‘FHEE__Create__regCode__new_reg_code’,’change_reg_code’, 10, 3);

2. Then I added this new REG_code which is my random lottery number to registrations table

add_filter( “FHEE_manage_event-espresso_page_espresso_registrations_columns”,”bc_filter_registration_list_table_columns”, 10, 2);

function bc_filter_registration_list_table_columns( $columns, $screen ) {

if ( $screen === “espresso_registrations_default” ) {
$columns[‘REG_code’] = ‘Lottery #’;
other columns come here …

}
return $columns;
}

add_action( “AHEE__EE_Admin_List_Table__column_REG_code__event-espresso_page_espresso_registrations”,”bc_registration_list_table_lottery_number”, 10, 2);

// Add lottery number
function bc_registration_list_table_lottery_number( $item, $screen ) {

if ( $screen === “espresso_registrations_default” && $item instanceof EE_Registration ) {

$reg_code = $item->reg_code();
echo $reg_code;
}
}

3. Add sorting by the lottery number (REG_code) column

function tw_ee_sortable_columns( $sortable_columns, $screen ) {

if ( $screen == ‘espresso_registrations_default’ ) {
$sortable_columns[‘REG_code’] = array(‘REG_code’ => TRUE);
}
return $sortable_columns;
}
add_filter(‘FHEE_manage_event-espresso_page_espresso_registrations_sortable_columns’, ‘tw_ee_sortable_columns’, 10, 2);

Issue – when I click on Lottery number column heading I get sorting by date instead.


bhesketh

May 8, 2018 at 8:47 am

here is the final url for the sorted column

http://secondsixties.chinooktech.com/wp-admin/admin.php?page=espresso_registrations&action=default&event_id=2292&default_nonce=c1a6bcbd19&orderby=REG_code&order=desc

but the list is still sorted by date


bhesketh

May 8, 2018 at 12:03 pm

it is always sorted by date if I enable sorting by any other custom column


Tony

  • Support Staff

May 8, 2018 at 3:44 pm

Hmm, ok.

Looks like we need a fix for this on our end, the orderby param is run through a switch to confirm which value is used and if the custom value doesn’t match any case there then it’s defaulting to use Reg_date.

I’ve created an issue for our developers to investigate this further.


bhesketh

May 8, 2018 at 11:59 pm

Thank you!


bhesketh

May 14, 2018 at 10:11 am

is there any update on this topic? thank you!


Tony

  • Support Staff

May 15, 2018 at 3:17 am

No updates yet.

We have a ticket for this which is in our queue and linked to this thread so we’ll post any updates here.

The support post ‘Sorting by custom column in Event's registration table’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3

Documentation for Event Espresso 4

Status: closed

Updated by  Tony 2 months ago ago

Topic Tags

Notifications

This topic is: not resolved
Do NOT follow this link or you will be banned from the site!
[i]
[i]