Welcome Guest, Not a member yet? Register   Sign In
Need help on Data grid with separate library to handel PHP, database and HTML, JS
#1

[eluser]geshan[/eluser]
I'm working on a Data Grid (back-end not JS) that mainly parses a SQL query (may be with joins) to a table and has lots of enhancements like displaying select, radio, image as per the fields. Now the problem is the library code is too heavy with both database and data handling, HTML (href etc) and even Javascript code (setting onclick form action, confirm on delete etc).

I want a suggestion if I can split the data grid library into two libraries, one that handles database and thing like sorting in the db, limit, pagination etc and the other that handles all the HTML (table, link) and JS (Onclick, confirm or even prototype AJAX) calls is that possible. How can I do it? Main question here is how do I make the data available (globally) to both libraries, please suggest.

Code:
PHP realated code in the library:

$query_res=$this->getResults($query);

function getResults($query){
        $query_exe=$this->CI->db->query($query);
    $query_res['no_of_rows']=$query_exe->num_rows();
    $this->total_rows=$query_res['no_of_rows'];


}

Code:
HTML and JS related code:
function tabulate($query_res){
        $tbl_open='<table border="1" cellpadding="4" cellspacing="0">';
            
         $tmpl = array (
                        'table_open'          => $tbl_open,
                        'table_close'         => '</table>'
                  );

        $this->CI->table->set_template($tmpl);
                            
        $this->CI->table->set_heading($query_res['field_names']);
        $this->fillTableData($query_res['res']);
        
            $attributes = array('class' => 'all_data', 'id' => 'all_data', 'name'=>'all_data');
            $hidden = array('operation'=>'save', 'save_href' => 'x');
        
            $frm_all_open=form_open($this->controller.'/all_data_get',$attributes,$hidden);
            $tabulated_res=$frm_all_open;
            $tabulated_res.=$this->CI->table->generate();
            $tabulated_res.=form_close();
            
        
        return $tabulated_res;
    $this->CI->table->clear();
}//function tablualte close


The JS related Code like:
if($action['title']=="Delete"){
                $link_to='&lt;a onclick="document.all_data.operation.value=\'Delete\';
                document.all_data.save_href.value=\''.$action['href'].'\';
                x=confirm(\'Are you Sure to Delete ?\'); if(x==true){document.getElementById(\''.$form_name_used.'\').submit()}" title="Delete selected" href="#"&gt;Delete</a>';
}


HELP ME with this.




Theme © iAndrew 2016 - Forum software by © MyBB