• Resolved chlustanec

    (@chlustanec)


    Hi,
    I have tables created with the help of this plugin/tutorial. However I cannot make them to treate numeric data as numeric data. So when I order the column with IDs, it is orderd like 1,10,11,12,2,3,4,5,6…

    data is pulled from database, ID is int. I even tried to add 0 during query, add 0 during feeding the table, tried +1-1 on both occasion as well, but those are still treated as string.

    Do anybody have any idea how to fix it? 🙂 thanks

    http://wordpress.org/plugins/custom-list-table-example/

Viewing 1 replies (of 1 total)
  • it happens because the sorting it’s based on arrays
    To sort on database data, you must to include in SQL query:

    private function table_data()
      {
        global $wpdb;
    
        // Set defaults
        $orderby = 'razon';
        $order = 'asc';
    
        // If orderby is set, use this as the sort column
        if(!empty($_GET['orderby']))
        {
            $orderby = $_GET['orderby'];
        }
    
        // If order is set use this as the order
        if(!empty($_GET['order']))
        {
            $order = $_GET['order'];
        }
        $sql = "SELECT * FROM ".DB_TABLE." ORDER BY ".$orderby." $order";
        $data = $wpdb->get_results($sql, ARRAY_A);
    
        return $data;
      }

    Replace line 363
    $data = $this->example_data;
    to
    $data = $this->table_data();

    Finnaly delete the usort_reorder() and usort functions.

Viewing 1 replies (of 1 total)
  • The topic ‘treat data as number for order pusrpose’ is closed to new replies.