⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Pagination / Search not working on large dataset



TechDaddies-Kevin
  • profile picture
  • Member

Posted 19 September 2013 - 08:55 AM

We have an odd issue. We have grocery crud running on dozens of pages without issue, but those tables have, at max, 2500 records. We are having problems ONLY with this one table.

 

We have roughly 12,000 records in the table.

We are using the flexgrid theme.

 

The first page of records loads perfectly.

However, searching does not work. When you attempt to search, nothing changes in the browser.

Pagination also does not work. When you go to a next page, records all disappear.

 

Before trying to paginate, the pagination says "Page 1 of 149"

After it says "Page 1 of 0"

 

What's worse is that once you have tried to go to the next page and it breaks, further reloads of the browser flash the records on the screen and then they immediately disappear. The only way to clear this problem and load the first screen of records is to clear your cookies.

 

There are no errors in the javascript console and no errors in the codeigniter log or the server's http error log. I am pretty much stumped here. We are using a custom model for this page, but the problem exists even without the model so I can only assume it has to do with the large record count. But the first screen loads very quickly and with no issues so I'm confused as to why further pages have issues.

 

Controller:

 

[php]public function index($customer = null)

    {

 

$crud = new grocery_CRUD();

        $crud->set_model('grocery_crud/Orders_crud');
 
        $crud->set_table('store_orders')->set_subject('Order');
        if(!empty($customer))
        {
            $crud->where('store_orders.user_id', $customer);
        }
 
        $crud->columns('shipping_first_name', 'shipping_last_name', 'transaction_id', 'subtotal','shipping', 'date', 'card');
 
        $crud->display_as('transaction_id', 'Order ID');
        $crud->unset_edit();
        $crud->unset_delete();
        $crud->unset_add();
        $crud->order_by('transaction_id', 'DESC');
        $crud->add_action('View Order', 'http://site.com/assets/admin/img/buttons/button_view_order.png' 'admin/orders/view');
 
        $output = $crud->render();
 
        $this->load->view('admin/view_user_orders', $output);
}

[/php]

 

Model (Though this problem happens even without loading the model

 

[php]class Orders_crud extends grocery_CRUD_Model

{
//The function get_list is just a copy-paste from grocery_CRUD_Model
    function get_list()
    {
        if($this->table_name === null)
            return false;
 
        $select = "`{$this->table_name}`.*";
        $select .= ", transactions.date, transactions.card";
 
        //set_relation special queries
        if(!empty($this->relation))
        {
            foreach($this->relation as $relation)
            {
                list($field_name , $related_table , $related_field_title) = $relation;
                $unique_join_name = $this->_unique_join_name($field_name);
                $unique_field_name = $this->_unique_field_name($field_name);
 
                if(strstr($related_field_title,'{'))
                {
                    $related_field_title = str_replace(" "," ",$related_field_title);
                    $select .= ", CONCAT('".str_replace(array('{','}'),array("',COALESCE({$unique_join_name}.",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $unique_field_name";
                }
                else
                {
                    $select .= ", $unique_join_name.$related_field_title AS $unique_field_name";
                }
 
                if($this->field_exists($related_field_title))
                    $select .= ", `{$this->table_name}`.$related_field_title AS '{$this->table_name}.$related_field_title'";
            }
        }
 
        //set_relation_n_n special queries. We prefer sub queries from a simple join for the relation_n_n as it is faster and more stable on big tables.
        if(!empty($this->relation_n_n))
        {
            $select = $this->relation_n_n_queries($select);
        }
 
        $this->db->select($select, false);
        $this->db->join('transactions', 'store_orders.transaction_id = transactions.id');
 
        $results = $this->db->get($this->table_name)->result();
 
        return $results;
    }
 
}

[/php]


TechDaddies-Kevin
  • profile picture
  • Member

Posted 20 September 2013 - 16:43 PM

For future searches, I FINALLY figured out what the problem was. It was hard to figure out because nothing was being logged in the error log.

 

The [php]public function index($customer = null)

[/php] was the culprit all along. If I remove the $customer=null part, everything works perfectly. It's very weird because we have used similar coding in other GC items and it works fine, but it's definitely the problem here.

 

So as a bandaid we simply made a new customer function to pull in customer-specific orders and all is well.


davidoster
  • profile picture
  • Member

Posted 20 September 2013 - 21:04 PM

Well there is a known problem of having the GC straight from the index function.

Check here, http://www.grocerycrud.com/documentation/known-issues


TechDaddies-Kevin
  • profile picture
  • Member

Posted 20 September 2013 - 21:05 PM

I've read that page and that never clicked. Thanks for the information