Skip to content

# Selecting Columns

By default, when we define the `->table` property, it displays all the columns of table.

### Customizing All Columns

We can pick certain columns to be displayed on grid by using `->set_columns($cols)` function.

    $col = array();
    $col["title"] = "Id"; // caption of column, can use HTML tags too
    $col["name"] = "client_id"; // grid column name, same as db field or alias from sql
    $col["width"] = "20"; // width on grid
    $col["editable"] = true;
    $cols[] = $col;

    $col = array();
    $col["title"] = "Name"; // caption of column, can use HTML tags too
    $col["name"] = "name"; // grid column name, same as db field or alias from sql
    $col["width"] = "40"; // width on grid
    $col["editable"] = true;
    $cols[] = $col;

    $col = array();
    $col["title"] = "Gender"; // caption of column, can use HTML tags too
    $col["name"] = "gender"; // grid column name, same as db field or alias from sql
    $col["width"] = "60"; // width on grid
    $col["editable"] = true;
    $cols[] = $col;

    // pass the cooked columns to grid
    $g->set_columns($cols);

### Customizing Desired Columns

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);

Only column with name 'company' will be changed to textarea and rest table column will be displayed as they were before.

NOTE: The first column must have unique data (usually PK) in order to work properly. It is required to identify and perform row wise operations. You can make it hidden in grid if you wish. See `hidden` property in later section for more.

### Resources

- Sample Code
- See Live Demo
- You can check this demo in archive `demos/appearance/image.php`