Welcome Guest, Not a member yet? Register   Sign In
CI Ignited-Datatables, wrong variable returning
#1

Hi, I'm using version 1.15 of the Ignited-Datatables to get data to JS Datatables using Ajax.

The problem I'm having is with the `edit_column` and `add_column` functions.

They are using a `$1` to get the variables inside the functions, like so:

Code:
edit_column('stato', renderStato('$1'), 'stato')
Where the `renderStato('$1')` function goes like this:
Code:
if(!function_exists('renderStato')){

    function renderStato($stato){

        if($stato == 1 || $stato == '1'){
            $stato = '-';
        }

        return $stato;

    }
}

Looks like the $1 variable is not getting validated correctly, as $1 is set to 1 but the library sees it as $1, so is never true.
How can I fix this?
Reply
#2

I think you have misinterpreted what they have done...

What you are doing is passing in a string instead of a variable as your parameter to the function renderStato().
As you have seen, it is passing in the literal string $1 as you have surrounded it in single quotes.
Stock standard PHP Programming rules apply, if you wrap anything in single quotes - it's the literal string. If you wrap a variable in double quotes - then it gets evaluated ( Big difference ) But in your case you do not need either.


So your call...

PHP Code:
edit_column('stato'renderStato('$1'), 'stato'); 
Should be

PHP Code:
edit_column('stato'renderStato($1), 'stato'); 

AND please do not use variable names like $1, that is a Huge NO NO! 
Rule of thumb: "Name a Variable What it is", even if it's a little long winded.
Reply
#3

I wrote a tutorial how to integrate DataTables and Editor in CodeIgniter 3. Maybe it is of any help to you, see http://ci.dubbel16.nl
Reply




Theme © iAndrew 2016 - Forum software by © MyBB