Welcome Guest, Not a member yet? Register   Sign In
Javascript and jquery
#4

[eluser]eokorie[/eluser]
Just a quick example - for the example I am just showing below, I was trying to setup jQuery datatables with CodeIgniter

Define your template as I suggested earlier on.

This the code I had in my controller:
Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
* @author [$username]
* @copyright [$year]
*/

class Javascript_Exp extends FrontController
{

    function __construct()
    {
        parent::__construct();
        $this->load->library('table');
        $this->load->library('javascript', array('js_library_driver' => 'scripto'));
        $this->load->model('blog_model');

    }

    function index()
    {
        $data = array();

        $data['library_src']  = $this->javascript->external('/assets/js/jquery/jquery.js', TRUE);
        $data['library_src'] .= $this->javascript->external('/assets/js/jquery/plugins/jquery.dataTables.js', TRUE);
        $data['library_src'] .= $this->javascript->external('/assets/js/jquery/plugins/TableTools.js', TRUE);
        $data['library_src'] .= $this->javascript->external('/assets/js/jquery/plugins/ZeroClipboard.js', TRUE);
        $data['library_src'] .= $this->javascript->external('/assets/js/jquery.ui/js/jquery-ui-1.8.9.custom.min.js', TRUE);

        $data['script_head'] = "";

        $limit = 10;
        $total = $this->blog_model->getArticles(array('count'=>TRUE));
        $offset = $this->uri->segment(4);

        if (!$this->input->is_ajax_request()) {
            $data['blog_entries'] = $this->blog_model->getArticles(array('iDisplayStart'=>$limit, 'iDisplayLength'=>$offset,
                                                                  'sortBy'=>'date_art', 'sortDirection'=>'desc'
            ));
        } else {
            $data['blog_entries'] = $this->blog_model->getArticles(array('limit'=>$limit, 'offset'=>$offset,
                                                                  'sortBy'=>'date_art', 'sortDirection'=>'desc'
            ));
        }


        $tmpl = array (
                    'table_open'          => '<table id="example" class="display" border="0" cellpadding="0" cellspacing="0" style="width: 100%">',
                    //'row_start'           => '<tr valign="top">',
                    //'row_alt_start'       => '<tr valign="top">',
                    'table_close'         => '</table>'
        );

        $this->table->set_template($tmpl);

        $table_data = array(form_checkbox('select_all', 'true', FALSE, 'class="toggle_all" id="select_all"'),
                            'ID',
                            'Article Title',
                            'Date Created',
                            'Status',
                            'Actions'

        );
        $this->table->set_heading($table_data);

        $config['base_url'] = base_url() . 'experiments/javascript_exp/index';
        $config['total_rows'] = $total;
        $config['per_page'] = $limit;
        $config['uri_segment'] = 4;
        // $config['page_query_string'] = TRUE;

        $this->pagination->initialize($config);

        $this->javascript->output(array(
            " $('#example').dataTable({
                'bJQueryUI': true,
                'bStateSave': true,
                //'sDom': 'T<\"clear\">lfrtip',
                //'sDom': '<\"H\"Tfr>t<\"F\"ip>',
                'sDom': 'T<\"clear\">lfrtip<\"clear spacer\">T',
                'oTableTools': {
                    'sSwfPath': '".base_url()."assets/js/jquery/plugins/copy_cvs_xls_pdf.swf',
                    'aButtons': [
                                    {
                                        'sExtends':    'text',
                                        'sButtonText': 'Add New',
                                        'sButtonClass': 'DTTT_button_new_item',
                                        'sButtonClassHover': 'DTTT_button_new_item_hover',
                                        'fnClick': function ( nButton, oConfig, oFlash ) {
                                            alert( 'Mouse click' );
                                        }
                                    },

                                    'copy', 'csv', 'xls', 'pdf','print',
                                    {
                                        'sExtends':    'collection',
                                        'sButtonText': 'Save',
                                        'aButtons':    [ 'csv', 'xls', 'pdf' ]
                                    }
                    ]
                }
            });

            $('.toggle_all').toggle(
                function(){
                    $('input.toggle').each(function() {
                        this.checked = true;
                    });
                }, function (){
                    var checked_status = this.checked;
                    $('input.toggle').each(function() {
                        this.checked = false;
                    });
                }
            );"

        )
        );

        $this->javascript->compile();

        $this->template->set_layout('one_column');
        $this->template->build('javascript/javascript_1',$data);
    }


}


Messages In This Thread
Javascript and jquery - by El Forum - 01-30-2011, 10:31 AM
Javascript and jquery - by El Forum - 01-30-2011, 02:32 PM
Javascript and jquery - by El Forum - 01-30-2011, 05:15 PM
Javascript and jquery - by El Forum - 01-30-2011, 05:46 PM
Javascript and jquery - by El Forum - 01-30-2011, 05:48 PM
Javascript and jquery - by El Forum - 01-31-2011, 12:17 AM
Javascript and jquery - by El Forum - 01-31-2011, 09:46 PM
Javascript and jquery - by El Forum - 02-01-2011, 03:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB