can we create columns of table with a function

Questionscan we create columns of table with a function
toki asked 7 years ago

Hi,

is it possible to create columns of table with a function as shown below.

I try but it does not.

function create_column($tit,$nam,$wid,$alg)
{
$col = array();
$col["title"] = $tit;
$col["name"] = $nam;
$col["width"] = $wid;
$col["align"] = $alg;
$col["search"] = true;
$cols[] = $col;

}
kolonyarat("Customer","Customer","50","right");

4 Answers
toki answered 7 years ago

Hi,

is it possible to create columns of table with a function as shown below.

I try but it does not.

function create_column($tit,$nam,$wid,$alg)
{
$col = array();
$col["title"] = $tit;
$col["name"] = $nam;
$col["width"] = $wid;
$col["align"] = $alg;
$col["search"] = true;
$cols[] = $col;

}

create_column("Customer","Customer","50","right");

Abu Ghufran answered 7 years ago

Yes you can, if you use global vars. e.g.

$cols = array();

function create_column($tit,$nam,$wid,$alg)
{
global $cols;

$col = array();
$col["title"] = $tit;
$col["name"] = $nam;
$col["width"] = $wid;
$col["align"] = $alg;
$col["search"] = true;
$cols[] = $col;
}

now calling create_column("Customer","Customer","50","right"); will store the cols in $cols array.

Finally, you can call

$grid->set_columns($cols); to pass that global variable to grid object.

Hope it helps.

toki answered 7 years ago

Hi Abu,

Yes, it works now.Thank you very much.

toki answered 7 years ago

Hi Abu,

Yes, it works now.Thank you very much.

Your Answer

8 + 11 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?