Format Field With Function
Consider the following table:
CREATE TABLE tblDemo(
pkID INT PRIMARY KEY AUTO_INCREMENT,
fldField1 VARCHAR(40),
fldField2 VARCHAR(40),
fldField3 VARCHAR(40),
fldCertainFields VARCHAR(40),
fldLongField TEXT
);
| fldField1 | fldField2 | fldCertainFields | fldLongField | Action |
|---|---|---|---|---|
| 3231233131 | qwe1e1 | Test detail | 1444 | |
| 34534534 | 3634634 | NEW Value | this is a long field | |
| -- | -- | My Awesome Value | -- | |
| 10 | 20 | This is another Value | 3345 | |
| ccvcxvxcxcxcxccxcx | xcxcxcxcxc | xcxcxcxcx | xcxcxcxzcxc |
Class Implementation:
#required file and class
require_once ('preheader.php');
include_once ('ajaxCRUD.class.php');
#this one line of code is how you implement the class
$tblDemo = new ajaxCRUD("New Item", "tblDemo", "pkID");
$tblDemo->omitPrimaryKey();
$tblDemo->formatFieldWithFunction('fldField1', 'makeBlue');
$tblDemo->formatFieldWithFunction('fldField2', 'makeBold');
#actually show to the table
$tblDemo->showTable();
function makeBold($val){
return "<b>$val</b>";
}
function makeBlue($val){
return "<span style='color: blue;'>$val</span>";
}
View Example by Itself
Click here to view example outside of the template.

Recent Feedback
" - Posted by gustavo on Friday Jan 8th, 2010 at 11:45am
One hint: if you define a relationship (defineRelationship) you cannot use formatFieldWithFunction to e.g. format the field with the changed display of the content "blue". I tried it with the field-name of the table and the related field name of the foreign table...
Best wishes, Martin " - Posted by Martin on Tuesday Aug 9th, 2011 at 4:48pm
How could I add pkid manually on add my item?" - Posted by Mollo on Saturday Nov 30th, 2013 at 6:58pm