Jump to content


Custom Query Pagination Problem - Solution

custom_query custom query limit pagination flexigrid

  • Please log in to reply
2 replies to this topic

#1 marlaaragao

marlaaragao

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 30 July 2015 - 02:24 PM

Hello!

 

I followed this topic: http://www.grocerycr...custom-queries/

to learn how to use custom queries. It's great! 

 

The problem is that the results did not respect pagination, so even when you have max 10 lines per page, it shows all the results. After some struggling, I managed to get the pagination working adding the 'limit' and 'get_total_results' functions. So if anyone is having this problem, the custom_model gets like this:

 
class Custom_Query_model extends grocery_CRUD_Model {

    private $query_str = '';

    function __construct() {
        parent::__construct();

    }

    function get_list() {
        
        $query = $this->db->query($this->query_str);

        $results_array = $query->result();
        return $results_array;
    }

    public function set_custom_query($query_str) {
        $this->query_str = $query_str;
    }

    /* Adding this does the trick for limiting the results per page! */
    function limit($value, $offset = ''){
        $this->query_str .= ' LIMIT '.($offset ? $offset.', ' : '').$value;
    }

    /* This method is to count the results of your query. If you don't add this
     * the total results on 'Displaying 1 to n of x items' can be wrong, 'cause 
     * grocery will get the total amount of rows from the table */
    function get_total_results() {
        return count($this->get_list());
    }

I tested in some of my tables that use custom query, and it's all good, but if anyone has other solution or find some error, please let me know. 

 

PS.: I'm creating new topic because the other one is a little old and it's not about pagination. Thank you very much!



#2 michaelh613

michaelh613

    Member

  • Members
  • PipPip
  • 16 posts

Posted 11 August 2015 - 02:41 PM

I see how pagination seems to work but filtering seems to be a problem.  Have you worked on that?



#3 marlaaragao

marlaaragao

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 09 September 2015 - 01:07 AM

I see how pagination seems to work but filtering seems to be a problem.  Have you worked on that?

 

Hello! Unfortunetly, I could not find a solution.. Sorry for the late response, but I was so busy at work, I kinda let the topic die. I can't find a solution, and I'm not with a lot of time to try to find it (knowing that I may not even get it). The search problem is more complicated. So, I hope someone can find it and share with us.. For now I'll take off the search boxes on the custom queries views.. Ugly (but that's what I've got for today, hehe).

 

Thank you!







Also tagged with one or more of these keywords: custom_query, custom, query, limit, pagination, flexigrid

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users