In the WordPress dashboard, the tables that displays the posts, pages and user data are all created internally by WordPress using the WP_List_Table PHP class.
WP_List_Table is base class for displaying a list of items in an ajaxified HTML table.
Throughout WordPress the class WP_List_Table is used to display data, e.g. users, plugins, comments, or posts. The class contains almost all necessary methods for displaying, sorting, paginating, and searching data.
Class WP_List_Table is found inside /wp-admin/includes/class-wp-list-table.php
. We will use this class to use table functionality of wordpress.
By using WP_List_Table class we can do these functions with a table –
- Set a basic wordpress table
- Sorting of tabular data
- Actions & Bulk actions of table
- Pagination
- Searching
- Screen Options
To use WP_List_Table class we need to extends this table class. By creating an instance of this class we can use all methods.
class Example_List_Table extends WP_List_Table {}
$example_obj = new Example_List_Table();
Here are the following methods provided by WP_List_Table to use –
Methods
- __call — Make private/protected methods readable for backward compatibility.
- __construct — Constructor.
- __get — Make private properties readable for backward compatibility.
- __isset — Make private properties checkable for backward compatibility.
- __set — Make private properties settable for backward compatibility.
- __unset — Make private properties un-settable for backward compatibility.
- _js_vars — Sends required variables to JavaScript land.
- ajax_response — Handles an incoming ajax request (called from admin-ajax.php)
- ajax_user_can — Checks the current user’s permissions
- bulk_actions — Displays the bulk actions dropdown.
- column_cb
- column_default
- comments_bubble — Displays a comment count bubble.
- current_action — Gets the current action selected from the bulk actions dropdown.
- display — Displays the table.
- display_rows — Generates the table rows.
- display_rows_or_placeholder — Generates the tbody element for the list table.
- display_tablenav — Generates the table navigation above or below the table
- extra_tablenav — Extra controls to be displayed between bulk actions and pagination.
- get_bulk_actions — Retrieves the list of bulk actions available for this table.
- get_column_count — Returns the number of visible columns.
- get_column_info — Gets a list of all, hidden, and sortable columns, with filter applied.
- get_columns — Gets a list of columns.
- get_default_primary_column_name — Gets the name of the default primary column.
- get_items_per_page — Gets the number of items to display on a single page.
- get_pagenum — Gets the current page number.
- get_pagination_arg — Access the pagination args.
- get_primary_column — Public wrapper for WP_List_Table::get_default_primary_column_name().
- get_primary_column_name — Gets the name of the primary column.
- get_sortable_columns — Gets a list of sortable columns.
- get_table_classes — Gets a list of CSS classes for the WP_List_Table table tag.
- get_views — Gets the list of views available on this table.
- handle_row_actions — Generates and display row actions links for the list table.
- has_items — Whether the table has items to display or not
- months_dropdown — Displays a dropdown for filtering items in the list table by month.
- no_items — Message to be displayed when there are no items
- pagination — Displays the pagination.
- prepare_items — Prepares the list of items for displaying.
- print_column_headers — Prints column headers, accounting for hidden and sortable columns.
- row_actions — Generates the required HTML for a list of row action links.
- search_box — Displays the search box.
- set_pagination_args — An internal method that sets all the necessary pagination arguments
- single_row — Generates content for a single row of the table.
- single_row_columns — Generates the columns for a single row of the table.
- view_switcher — Displays a view switcher.
- views — Displays the list of views available on this table.
We will use above methods to work with wordpress WP_List_Table.