Skip to content

Ajax Formater Grid Issue #39

Description

@mangopik

on next version we will change GridFormater function

edit file /application/helpers/ajax_helper.php

change old function gridFormater() with following code

    public static function gridFormater($val , $row, $attribute = array() , $arr = array()) {
        $_this = & get_Instance();
        // Handling Image & file Field
        if($attribute['image']['active'] =='1' && $attribute['image']['active'] !='') {
            $val =  SiteHelpers::showUploadedFile($val,$attribute['image']['path']) ;
        }
        // Handling Quick Display As 
        if(isset($arr['valid']) && $arr['valid'] ==1)
        {
            $fields = str_replace("|",",",$arr['display']);
            $Q = $_this->db->query(" SELECT ".$fields." FROM ".$arr['db']." WHERE ".$arr['key']." = '".$val."' ")->row();
            if(count($Q) >= 1 )
            {
                $rowObj = $Q;
                $fields = explode("|",$arr['display']);
                $v= '';
                $v .= (isset($fields[0]) && $fields[0] !='' ?  $rowObj->$fields[0].' ' : '');
                $v .= (isset($fields[1]) && $fields[1] !=''  ? $rowObj-> $fields[1].' ' : '');
                $v .= (isset($fields[2]) && $fields[2] !=''  ? $rowObj->$fields[2].' ' : '');


                $val = $v;
            } 
        }   

        // Handling format function     
        if(isset($attribute['formater']['active']) and $attribute['formater']['active']  ==1)
        {
            $val = $attribute['formater']['value'];
            foreach($row as $k=>$i)
            {
                if (preg_match("/$k/",$val))
                    $val = str_replace($k,$i,$val);             
            }
            $c = explode("|",$val);
            if(isset($c[0]) && class_exists($c[0]))
            {
                $arguments = explode(":",$c[2]); 
                $val = call_user_func( array($c[0],"$c[1]"), $arguments); 
            }   

        }
        // Handling Link  function  
        if(isset($attribute['hyperlink']['active']) && $attribute['hyperlink']['active'] ==1 && $attribute['hyperlink']['link'] != '')
        {   

            $attr = '';
            $linked = $attribute['hyperlink']['link'];
            foreach($row as $k=>$i)
            {

                if (preg_match("/$k/",$attribute['hyperlink']['link']))
                    $linked = str_replace($k,$i, $linked);              
            }
            if($attribute['hyperlink']['target'] =='modal')
            {
                $attr = 'onclick="SximoModal(this.href,\''.addslashes ($val).'\'); return false"';
            }

            $val =  "<a href='".site_url($linked)."' $attr style='display:block' >".$val." <span class='fa fa-arrow-circle-right pull-right'></span></a>";
        }



        return $val;

    }

Usage

Class Function


class FormaterHelpers
{
      // function with 1 arguments
    public static  function myfunc_one( $args ){
        return $args[0];
    }

     // function with 2 arguments
    public static  function myfunc_two( $args ){
        return $args[0]." and ".$args[1]."; 
    }

}               

Usage 1

FormaterHelpers|myfunc_one|field  

Usage 2

FormaterHelpers|myfunc_two|field:field2 

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions