Any way to capture the the query for a particular render or search?
- Single Page
Posted 22 March 2012 - 00:01 AM
I'm lovin' grocery crud, but I have a quick question. I'm writing an application that exports CSV files from results, and I was wondering if there was any way to capture the query used to generate a particular set of results (so I can use this query to generate a CSV using codeigniter's built-in function)? I experimented with calling $this->db->last_query() after the get_list() method in the crud model and storing this query in the session for later use, but alas, I knew it wouldn't be that simple. Any guidance would be much appreciated.
Thanks, and great work!
Paul
Posted 29 March 2012 - 05:36 AM
I created a "get_csv" method which is essentially a copy of the "ajax_list" function, except that it redirects the current query's result output (with the limit set to all results, rather than just the per page value) to the browser as a csv file using modified headers and the "csv_from_result()" CI dbutil method. Next I created an "Export as CSV" link in the list_template view that, when clicked, unbinds the "Search" button's submit handler and changes the search form's action to the /get_csv URL and submits to this via a regular POST--since the csv is output to the browser with the correct headers, a download dialog appears instead of actually redirecting to that page. The search form's action is then reset to its original value and rebound to the ajax submit. I also integrated the multi-filter search functionality described here: http://www.grocerycr...s-on-flexigrid/ which is working splendidly as well, allowing for easy filtering of the dataset before exporting as a csv.
Hope this information is helpful to those looking integrate csv export into their project.
--Paul
Posted 29 March 2012 - 05:52 AM
I think that your way is the right one. I would suggest the same thing and I am happy that you figured out by yourself. If you need any other help with this, just post it here.
Kindest Regards
John
Posted 30 May 2012 - 20:42 PM
OK, got this figured out. If I finally get some free time in the near future, I'll try to post my solution in the extensions forum. The overall strategy went like this:
I created a "get_csv" method which is essentially a copy of the "ajax_list" function, except that it redirects the current query's result output (with the limit set to all results, rather than just the per page value) to the browser as a csv file using modified headers and the "csv_from_result()" CI dbutil method. Next I created an "Export as CSV" link in the list_template view that, when clicked, unbinds the "Search" button's submit handler and changes the search form's action to the /get_csv URL and submits to this via a regular POST--since the csv is output to the browser with the correct headers, a download dialog appears instead of actually redirecting to that page. The search form's action is then reset to its original value and rebound to the ajax submit. I also integrated the multi-filter search functionality described here: http://www.grocerycr...s-on-flexigrid/ which is working splendidly as well, allowing for easy filtering of the dataset before exporting as a csv.
Hope this information is helpful to those looking integrate csv export into their project.
--Paul
[/quote]
Hi .. can you please share your code.
Thanks!