WP_LIST_TABLE显示的太宽了…右侧溢出

问题描述 投票:0回答:1

我有一个用于在管理后端中显示表格的类;但是桌子从右边溢出了,我不确定为什么。我的数据没有填满单元格,也没有任何代码设置宽度。我选择了另一个效果很好的插件,并对其进行了修改以进行一些改进。显然,我所做的某件事导致了问题,但我不知道该怎么办。

这是我的课程...

<?php

// Link to core WordPress class
if(!class_exists('WP_List_Table')){
    require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
}




//Create a new class to extend the core WP_List_Table class
class GJ_Signature_Table extends WP_List_Table
{
    var $singular               =   "signature";
    var $plural                 =   "signatures";
    var $content_before         =   "Content before table";
    var $content_after          =   "Content after table";
    var $per_page               =   50;
    var $all_columns            =   array("First_Name" => "First Name","Last_Name" => "Last_Name","Email" => "Email");
    var $unique_column          =   "Record"; //Should be a primary key in the database
    var $default_sort_column    =   "First_Name"; //If no sort criteria is set, use this column





    function extra_tablenav( $which )
    {
        if ( $which == "top" ){
            //The code that goes before the table is here
            echo $this->content_before;
        }
        if ( $which == "bottom" ){
            //The code that goes after the table is there
            echo $this->content_after;
        }
    }

    function column_First_Name($item)
    {

        //Build row actions
        $actions = array(
            'edit'      => sprintf('<a href="?page=%s&action=%s&'.$this->singular.'=%s">Edit</a>',$_REQUEST['page'],'edit',$item[$this->unique_column]),
            'delete'    => sprintf('<a href="?page=%s&action=%s&'.$this->singular.'=%s">Delete</a>',$_REQUEST['page'],'delete',$item[$this->unique_column]),
        );

        //Return the title contents
        return sprintf('%1$s <span style="color:silver">(id:%2$s)</span>%3$s',
            /*$1%s*/ $item['First_Name'],
            /*$2%s*/ $item[$this->unique_column],
            /*$3%s*/ $this->row_actions($actions)
        );
    }


    function process_bulk_action()
    {

        //Detect when a bulk action is being triggered...
        if( 'delete'===$this->current_action() )
        {
            foreach($_REQUEST as $key => $value)
            {
                if(is_array($value))
                {
                    foreach ($value as $key2=>$value2)
                    {
                        echo "<p>".$key." ARRAY: ".$key2.": ".$value2."<p>";
                    }
                }
                else
                {
                    echo "<p>".$key.": ".$value."<p>";
                }
            }
            wp_die('A process to delete the records will be added here soon');
        }

    }







        /*      NORMALLY YOU DO NOT NEED TO EDIT BELOW THIS LINE       */









    //Required
    function __construct()
    {
        global $status, $page;

        //Set parent defaults
        parent::__construct( array(
            'singular'  => $this->singular,     //singular name of the listed records
            'plural'    => $this->plural,       //plural name of the listed records
            'ajax'      => false                //does this table support ajax?
        ) );

    }


    //Recommended
    /*
    //Individual colums can be specied in this option to have a default method
    function column_default($item, $column_name)
    {
        switch($column_name){
            case 'rating':
            case 'director':
                return $item[$column_name];
            default:
                return print_r($item,true); //Show the whole array for troubleshooting purposes
        }
    }
    */
    // This option will create a default method for all columns
    function column_default($item, $column_name)
    {
        switch($column_name){
            case $column_name:
                return $item[$column_name];
            default:
                return print_r($item,true); //Show the whole array for troubleshooting purposes
        }
    }

    //Required
    function column_cb($item)
    {
        return sprintf(
            '<input type="checkbox" name="%1$s[]" value="%2$s" />',
            /*$1%s*/ $this->_args['singular'],      //Let's simply repurpose the table's singular label
            /*$2%s*/ $item[$this->unique_column]    //The value of the checkbox should be the record's unique identifier
        );
    }

    //Required
    /*
    // Specify individual colums using this option
    function get_columns()
    {
        $columns = array(
            'cb'        => '<input type="checkbox" />', //Render a checkbox instead of text
            'title'     => 'Title',
            'rating'    => 'Rating',
            'director'  => 'Director'
        );
        return $columns;
    }
    */
    //Use all colums using this option
    function get_columns()
    {
        $columns = array('cb' => '<input type="checkbox" />'); //Render a checkbox instead of text

        foreach ($this->all_columns as $key => $value)
        {
            $columns[$key]=$value;
        }
        return $columns;
    }


    //Optional
    /*
    //Specify individual columns using this option
    function get_sortable_columns()
    {
        $sortable_columns = array(
            'title'     => array('title',false),     //true means it's already sorted
            'rating'    => array('rating',false),
            'director'  => array('director',false)
        );
        return $sortable_columns;
    }
     */
    //Make all colums sortable using this option
    function get_sortable_columns()
    {
        foreach ($this->all_columns as $key => $value)
        {
            $sortable_columns[$key] = array($key,false);
        }
        return $sortable_columns;
    }


    //Optional
    function get_bulk_actions()
    {
        $actions = array(
            'delete'    => 'Delete',
        );
        return $actions;
    }


    //Required

    function prepare_items()
    {
        global $wpdb; //This is used only if making any database queries

        //First, lets decide how many records per page to show
        $per_page = $this->per_page;

        //REQUIRED. Now we need to define our column headers.
        $columns = $this->get_columns();
        $hidden = array();
        $sortable = $this->get_sortable_columns();

        //REQUIRED. Finally, we build an array to be used by the class for column headers.
        $this->_column_headers = array($columns, $hidden, $sortable);

        //Optional. You can handle your bulk actions however you see fit. In this case, we'll handle them within our package just to keep things clean.
        $this->process_bulk_action();

        //Get data from the databasw
        global $GJ_Petition_TABLE_signatures;
        $sql = "SELECT * FROM ".$GJ_TABLE_signatures;
        $data = $wpdb->get_results( $sql, 'ARRAY_A' );


        /**
        * This checks for sorting input and sorts the data in our array accordingly.
        *
        * In a real-world situation involving a database, you would probably want
        * to handle sorting by passing the 'orderby' and 'order' values directly
        * to a custom query. The returned data will be pre-sorted, and this array
        * sorting technique would be unnecessary.
        */
        $default_sort_column=$this->default_sort_column;
        function usort_reorder($a,$b){
            $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : $default_sort_column; //If no sort, default to specified default
            $order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'asc'; //If no order, default to asc
            $result = strcmp($a[$orderby], $b[$orderby]); //Determine sort order
            return ($order==='asc') ? $result : -$result; //Send final sort direction to usort
        }
        usort($data, 'usort_reorder');


        //REQUIRED for pagination.
        $current_page = $this->get_pagenum();

        //REQUIRED for pagination.
        $total_items = count($data);


        /**
        * The WP_List_Table class does not handle pagination for us, so we need
        * to ensure that the data is trimmed to only the current page. We can use
        * array_slice() to
        */
        $data = array_slice($data,(($current_page-1)*$per_page),$per_page);

        //REQUIRED. Now we can add our *sorted* data to the items property, where it can be used by the rest of the class.
        $this->items = $data;

        //REQUIRED. We also have to register our pagination options & calculations.
        $this->set_pagination_args( array(
            'total_items' => $total_items,                  //WE have to calculate the total number of items
            'per_page'    => $per_page,                     //WE have to determine how many items to show on a page
            'total_pages' => ceil($total_items/$per_page)   //WE have to calculate the total number of pages
        ) );
    }


}



?>

在调用它时,我也没有做任何时髦的事情...

    function GJ_signatures()
    {

        //Prepare Table of elements
        $GJ_Signature_Table = new GJ_Signature_Table();
        $GJ_Signature_Table->prepare_items();


        //Table of elements
       // $GJ_Signature_Table->display();
?>

        <form id="signatures" method="get">
            <!-- For plugins, we also need to ensure that the form posts back to our current page -->
            <input type="hidden" name="page" value="<?php echo $_REQUEST['page'] ?>" />
            <!-- Now we can render the completed list table -->
            <?php $GJ_Signature_Table->display() ?>
        </form>
<?php
    }
wordpress
1个回答
0
投票

当我错过简单的事情时,我讨厌它...需要用<form>包围<div>

<div class="wrap"><form.....></form></div>

© www.soinside.com 2019 - 2024. All rights reserved.