⚠ In case you've missed it we are migrating 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 forum is read-only and soon will be archived. ⚠


Member Since 06 Jun 2015
Offline Last Active May 11 2016 01:29 AM

Topics I've Started

Change date format dynamically for each client based on clients configuration

23 October 2015 - 03:58 PM



This may sound dumb, but I wonder if there's a way to change the date format based on users configuration. I tried doing this on the callback_after_update of the configuration model:

$ci = &get_instance();
$ci->config->set_item('grocery_crud_date_format', $post_array['date_format'] == 'Y-m-d' ? 'sql-date' : 
                    ($post_array['date_format'] == 'd/m/Y' ? 'uk-date' : 'us-date'));

But it does no work. The date_format is always the one from the config file.

I know I can do a callback for each date field in my program, but I want to know if there's a simpler way to acomplish this. Any ideas? Thanks very much!

Wrong true_false value for column

21 October 2015 - 12:22 PM



I noticed a strange behavior in one of my tables: the column receives a wrong value for a true_false (db type TINYINT) field. On the edit form, the value is correct.


I have a column 'is_active' (0 when not active and 1 when active).
When a entry is not active, even tho the value is 0 on db, the column on list action receives the value 1 (I saw the problem and tested with a callback).
Does anyone have an idea why is this happening? I know probably is not on grocery_crud, since other tables have the correct behavior, but I was hoping someone could give a little hand figuring this out.


The edit form receives the right value*.





Bootstrap Theme - Unset Search by Column

09 September 2015 - 12:56 AM



Is there a way to unset the search box in some or all the columns in Bootstrap Theme? 


How to implement XSS Protection using Grocery Crud

07 August 2015 - 12:19 AM



I wonder how I'm able to prevent xss atacks on grocery crud by filtering the output. I can't use the Codeigniter feature, since it's deprecated and they say you should filter the output data, not the data that will be stored on db.


If I save some post that is for example: '<script>alert("that's not good")</script>', when I'm in the grid, if this column is shown, the script is executed. How can I prevent it?


Again, I can't change the data before saving on db. Thanks!



Custom Query Pagination Problem - Solution

30 July 2015 - 02:24 PM



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() {


    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!