Format single column only?

QuestionsFormat single column only?
Gary Brett asked 10 years ago

Hi there, I have a table with 20 columns, 3 of these are date columns, is there any way to format these into UK style without having to include every column?

I can achieve what I need by adding ;
$col = array();
$col["title"] = "DOB"; // caption of column
$col["name"] = "DOB"; // grid column name
$col["formatter"] = "date";
$col["formatoptions"] = array("srcformat"=>'Y-m-d',"newformat"=>'d/m/Y');
$col["editable"] = true;
$cols[] = $col;

However now the page only outputs that column unless I add all 19 other columns in this style? Is there a way to avoide this?

Kind regards

Gary

7 Answers
Gary Brett answered 10 years ago

Hi again, forgot to add I tried using $g->set_columns($cols,true); under the above code and error returned 'Length of col names <> colmodel!'

// caption of column
$col = array();
$col["title"] = "DOB"; // caption of column
$col["name"] = "DOB"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["formatter"] = "date";
$col["formatoptions"] = array("srcformat"=>'Y-m-d',"newformat"=>'d/m/Y');
$col["editable"] = true;
$cols[] = $col;

$g->set_columns($cols,true);

Thank you

Abu Ghufran answered 10 years ago

If you want to customize any specific column properties, and let other columns be displayed from table definition, you can pass 2nd argument of `set_columns($cols,true)` to `true`.

$col = array();
$col["name"] = "company";
$col["edittype"] = "textarea";
$cols[] = $col;

$g->set_columns($cols,true);

Abu Ghufran answered 10 years ago

Sorry for the last reply, saw your second update late.

Please make sure $cols is not reused before you use in grid set_columns.
OR just put $cols = array(); before it.

Gary Brett answered 10 years ago

Thanks Abu appreciate your fast response, did it manually on this occasion so will try again on next grid.

Gary

Gary Brett answered 10 years ago

Hi Abu, sorry I am just not getting this, I have tried all combinations but just returns the same error of 'Length of col names <> colmodel!'

Tried;
// show all other columns after single column format
$col = array();
$g->set_columns($cols,true);
$cols[] = $col;

// show all other columns after single column format
$col = array();
$g->set_columns($cols,true);

// show all other columns after single column format
$g->set_columns($cols,true);
$cols[] = $col;

// show all other columns after single column format
$g->set_columns($cols,true);

Any ideas or is there a demo where this occurs so I can compare code?

Thank you

Gary Brett answered 10 years ago

Thanks Abu, I had to comment out // pass the cooked columns to grid
//$g->set_columns($cols);

Then it worked.

Kind Regards

Gary

Your Answer

15 + 17 =

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?