Jump to content


jjwdesign

Member Since 08 Dec 2012
Offline Last Active Jun 12 2013 03:47 AM
-----

Posts I've Made

In Topic: Ajax Pagination/Search with Datatables Theme

12 June 2013 - 03:47 AM

Rad,

 

If I understand you correctly, you want to use Datatables in the AJAX per page style of data loading rather than trying to use all of the data at one time - as it currently is with the Datatables theme. I've started down this development path to see how difficult it would be. I have not gotten this to work, but it looks possible.

 

First, I copied the "datatables" them to "datatables_ajax".  I then figured out that the list.php view can be used to output the JSON aaData that Datatables uses as it's source ({controller}/index/ajax_list - action). The list_template.php on the other hand is where many of the controls are located. I have not gotten any further... Maybe some day I will continue the efforts. Good luck!

 

The code below has a few hacks in it, but it does load the AJAX data from list.php into the Datatable.

<?php
// Determine admin status and route
$ci =& get_instance();
$controller = $ci->router->fetch_class(); // class = controller
$method = $ci->router->fetch_method();

$base_url_to_replace = site_url('');

// Make JSON Data (aaData) for Datatables

// Format List Data for Datatables aaData
$datatables_data = array();

$datatables_data = array();

foreach ($list as $num_row => $row)
{
    $datatables_row = array();
    foreach ($columns as $column)
    {
        $datatables_row[] = $row->{$column->field_name};
    }
    
    $actions_value = '';
    if (!$unset_delete || !$unset_edit || !empty($actions))
    {
        if (!empty($row->action_urls))
        {
            foreach ($row->action_urls as $action_unique_id => $action_url)
            {
                // JJW - Cutom url hack
                $action_url = str_replace($base_url_to_replace, '/', $action_url);
                $action = $actions[$action_unique_id];
                // JJW - custom target hack
                $target = (preg_match('/desc/i', $action->label) || preg_match('/note/i', $action->label)) ? ' target="_blank"' : '';
                
                $actions_value .= '<a href="'.$action_url.'" class="edit_button ui-button ui-widget ui-state-default ui-corner-all '.
                    'ui-button-text-icon-primary target_blank_class" role="button"'.$target.'>'.
                    '<span class="ui-button-icon-primary ui-icon '.$action->css_class.' '.$action_unique_id.'"></span><span '.
                    'class="ui-button-text">&nbsp;'.$action->label.'</span></a>';
            }
        }
        
        if (!$unset_edit)
        {
            $actions_value .= '<a href="'.$row->edit_url.'" class="edit_button ui-button ui-widget ui-state-default ui-corner-all '.
                'ui-button-text-icon-primary" role="button"><span class="ui-button-icon-primary ui-icon ui-icon-pencil"></span>'.
                '<span class="ui-button-text">&nbsp;'.$this->l('list_edit').'</span></a>';
        }
        if (!$unset_delete)
        {
            $actions_value .= '<a onclick = "javascript: return delete_row(''.$row->delete_url.'', ''.$num_row.'')" '.
                'href="javascript:void(0)" class="delete_button ui-button ui-widget ui-state-default ui-corner-all '.
                'ui-button-text-icon-primary" role="button">'.
                '<!-- span class="ui-button-icon-primary ui-icon ui-icon-circle-minus" /span -->'.
                '<span class="ui-button-text" style="padding: 0.4em 0.5em 0.4em 0.5em;">'.
                // JJW Hack X for $this->l('list_delete');
                'X</span></a>';
        }
        
        $datatables_row[] = $actions_value;
    }
    
    $datatables_data[] = $datatables_row;
}
$datatables_data = array('aaData' => $datatables_data);

//$ci->output->set_content_type('application/json');
echo json_encode($datatables_data);


In Topic: AJAX Listing View? Multiple Listing Views?

31 May 2013 - 03:33 PM

Probably on the next version of GC.

 

That's great to hear. I'll be sending in my donation soon!


In Topic: Ajax instead of iframe

24 May 2013 - 10:03 PM

I'd be interested in seeing this change/feature added to Grocery CRUD as well.


In Topic: Filter without display in coloumn

27 April 2013 - 04:51 PM

Yes, there is a way of doing it. Use the callback_column() method to revise the column details. For example, my title column was changed to add some additional search keywords (ie display: none) to make the JavaScript search functionality of datatables search better.

 

http://www.grocerycr...callback_column

 

Add the call back for the existing title column.

 

$crud->callback_column('title', array($this, '_rev_title'));

 

Use the callback to add the keywords into the column with style display none.

 

    function _rev_title($value, $row) {
        
        return htmlspecialchars($value) . 
            '<span style="display:none;"> ' . 
            htmlspecialchars(str_replace(',',' ', $row->search_keywords)) . 
            ' </span>';
    }

 

I used a Keyword Generating library to create the keywords. You don't have to use the keywords. You can use whatever fields you wish to add into the hidden span.

 

https://github.com/p...yword-generator

 

To generate the keywords on edit/add save. You'll need to look at several more callbacks. Something like...

 

$crud->callback_after_insert(array($this, '_callback_after_insert'));

$crud->callback_after_update(array($this, '_callback_after_update'));

 

But, I'll leave that up to you.


In Topic: I have question about set relation 1_n for more that 2 tables

27 April 2013 - 04:38 PM

Grocery CRUD only has the two relationship methods that I know of.

 

http://www.grocerycr...ns/set_relation

and

http://www.grocerycr..._a_relation_n_n

 

But, you can create your own methods for the data you need. You need to develop your own model methods to get the data needed to fill your table columns.

 

http://www.grocerycr...callback_column

 

==========

 

For example, your customer group column.

 

$crud->callback_column('cutomer_group_name', array($this, '_cutomer_group_name_callback'));

 

 

Then in your controller, create method for the callback function.

 

function _cutomer_group_name_callback($value, $row) {

    ...write your custom SQL code here... (your custom model method)

}