Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the community forum?
All Topics
Nicolai

Enable Filtering for New Column Type

I successfully created a new column type following your guide here. Your guide shows how to make the new column type Sortable and Editable – but not how to enable Filtering.

Please advice: how can I enable Filtering for a new column type?

9 months, 2 weeks ago
Stefan
Developer

Filtering is not that easy to implement as editing and sorting and it almost always requires custom logic.
That’s the reason that there is not a default implementation for this in the toolkit.
Currently, there are two ways to filter column in our plugin.

1) Filtering with the drop down options on the table screen
2) The new Smart Filtering feature (https://www.admincolumns.com/smart-filtering-wordpress-content/)

Both solutions require a method in the column class that tells which model must be loaded.
Let’s take a numeric custom field and implement that already present model for that field.

For filtering it looks like

public function filtering() {
	return new ACP\Filtering\Model\CustomField\Numeric( $this );
}

for smart filtering it’s easier and it looks like:

public function search() {
	return new ACP\Search\Comparison\Meta\Numeric( $this->get_meta_key(), $this->get_meta_type() );
}

For the actual logic of the models and comparison you’ll need to have a look at the many examples in our code.

9 months, 1 week ago

You must be logged in to reply to this topic.