⚠ 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

Any way to capture the the query for a particular render or search?



pepster

pepster
  • profile picture
  • Member

Posted 22 March 2012 - 00:01 AM

Hi,

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

pepster

pepster
  • profile picture
  • Member

Posted 29 March 2012 - 05:36 AM

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

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 29 March 2012 - 05:52 AM

Thanks Paul and sorry for not answering you. Believe it or not, I wanted to answer you and I couldn't find some time to do it.
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

telnasser

telnasser
  • profile picture
  • Member

Posted 30 May 2012 - 20:42 PM

[quote name='pepster' timestamp='1332999368' post='972']
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!