I want to render columns with actions.
When hover on row, Edit | Delete
links show.
Problem at function column_name($item)
.
I don’t know why don’t run to this function.
I tried to add wp_die()
into this function but don’t have anything change.
I written class extend WP_List_Table
:
class Custom_Table_Example_List_Table extends WP_List_Table
{
function __construct()
{
global $status, $page;
parent::__construct(array(
'singular' => 'dathangnhanh',
'plural' => 'dathangnhanhs',
));
}
/**
* [OPTIONAL] this is example, how to render column with actions,
* when you hover row "Edit | Delete" links showed
*
* @param $item - row (key, value array)
* @return HTML
*/
function column_name($item)
{
// links going to /admin.php?page=[your_plugin_page][&other_params]
// notice how we used $_REQUEST['page'], so action will be done on curren page
// also notice how we use $this->_args['singular'] so in this example it will
// be something like &dathangnhanh=2
$actions = array(
'edit' => sprintf('<a href="https://wordpress.stackexchange.com/questions/279989/?page=persons_form&id=%s">%s</a>', $item['id'], __('Edit', 'cltd_example')),
'delete' => sprintf('<a href="?page=%s&action=delete&id=%s">%s</a>', $_REQUEST['page'], $item['id'], __('Delete', 'cltd_example')),
);
return sprintf('%s %s',
$item['madonhang'],
$this->row_actions($actions)
);
}
/**
* [REQUIRED] This method return columns to display in table
* you can skip columns that you do not want to show
* like content, or description
*
* @return array
*/
function get_columns()
{
$columns = array(
'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
'id' => __('STT', 'cltd_example'),
'madonhang' => __('Mã Đơn Hàng', 'cltd_example'),
'hoten' => __('Họ Tên', 'cltd_example'),
'sdt' => __('Số Điện Thoại', 'cltd_example'),
'email' => __('Email', 'cltd_example'),
'tensp' => __('Tên Sản Phẩm', 'cltd_example'),
'diachinhan' => __('Địa Chỉ Nhận', 'cltd_example'),
'soluong' => __('Số Lượng', 'cltd_example'),
'thanhtien' => __('Thành Tiền', 'cltd_example'),
);
return $columns;
}
}