Skip to content

Display data from other columns with customer formatter

You will need custom formatter to manipulate column to add other data. It is achieved using column property function.

The example below demonstrates concatenating first and last name as full name displayed inside firstName column . 

<?php
$dg = new C_DataGrid("SELECT firstName, lastName, age FROM table1", "id", "table1");

$dg->set_col_property('firstName', array('formatter'=>'###nameFormatter###')); // must have ###

$dg->display();
?>

<script type="text/javascript">
function(cellvalue, options, rowObject){
    return rowObject["firstName"] + ' ' + rowObject["lastName"];
}
</script>

Mind you that a custom column is not editable. 

This function is extremely versatile. You will fall in love with set_col_property and use it extensively.

Feedback and Knowledge Base