higrid.net


hiGrid\jqGrid
hgGrid.php at line 48

Class jqGrid

jqGrid
All Known Subclasses:
hgGridEdit

public abstract class jqGrid

Author:
She Yi [email protected]
Copyright:
HiGrid.net
Version:
2.1

Field Summary
string

$ExportCommand

Set the sql command for excel export.

string

$SubgridCommand

Set a sql command used for the simple subgrid

boolean

$cacheCount

mixed

$customClass

Custom call can be used again with custom function customFunc.

mixed

$customError

function

$customFunc

Custom function which can be called to modify the grid output.

string the

$dataType

The output format for the grid.

array

$datearray

Store the names which are dates.

boolean

$debug

Enable disable debuging

string

$encoding

Default enconding passed to the browser

string

$errorMessage

Last error message from the server

integer

$gSQLMaxRows

Maximum number of rows to be exported for the excel export

string

$higridSC

In case if no table is set, this holds the sql command for retrieving the data from the db to the grid

boolean

$jsonencode

If set to true uses the PHP json_encode if available.

boolean

$logtofile

Determines if the log should be written to file or echoed.

array

$mongofields

Array which set which fields should be selected in case of mongodb.

array

$mongointegers

Store the names for the int fields when database is MongoDB.

mixed

$oper

boolean

$optimizeSearch

Optimizes the search SQL when used in MySQL with big data sets.

boolean

$performcount

Internal set in queryGrid if we should use count query in order to set the grid output

boolean

$readFromXML

Obtain the SQL qurery from XML file.

boolean

$showError

If set to true all errors from the server are shown in the client in a dialog.

string

$table

set a table to display a data to the grid

string

$version

Get te current version

boolean

$xmlCDATA

Defines if the xml otput should be enclosed in CDATA when xml output is enabled

Constructor Summary
void

__construct(mixed db, str odbctype, resource -)

Constructor

Method Summary
void

logQuery(string sql, array data, array types, mixed input, mixed fld, str primary)

Log query

void

debugout()

Prints all executed SQL queries to file or console

void

sendErrorHeader()

Function to simulate 500 Internal error so that it sends the error to the client.

protected string

parseSql(string sqlElement, array params, bool bind)

Prepares a $sqlElement and binds a parameters $params Return prepared sql statement

protected boolean

execute(string sqlId, array params, resource sql, boolean limit, integer nrows, integer offset, str order, str sort)

Executes a prepared sql statement.

protected mixed

getSqlElement(string sqlId)

Read a xml file and the higridSC and return the sql string Return string if the query is found false if not.

protected object

queryForObject(string sqlId, array params, boolean fetchAll)

Return the object from the query

protected array

getStringForGroup(object group, array prm)

Recursivley build the sql query from a json object

mixed

buildSearch(string filter, string otype)

Build a search string from filter string posted from the grid Usually use this functio separatley

string

getUserDate()

Return the current date format used from the client

void

setUserDate(string newformat)

Set a new user date format using PHP convensions

string

getUserTime()

Return the current datetime format used from the client

void

setUserTime(string newformat)

Set a new user datetime format using PHP convensions

string

getDbDate()

Return the current date format used in the undelayed database

void

setDbDate(string newformat)

Set a new database date format using PHP convensions

string

getDbTime()

Return the current datetime format used in the undelayed database

void

setDbTime(string newformat)

Set a new database datetime format using PHP convensions

array

getGridParams()

Return the associative array which contain the parameters that are sended from the grid to request, search, update delete data.

void

setGridParams(array _aparams)

Set a grid parameters to identify the action from the grid Note that these should be set in the grid - i.e the parameters from the grid should equal to the GridParams.

object

selectLimit(string limsql, integer is, array array, int nrows, int offset, mixed params, str order, str sort)

Will select, getting rows from $offset (1-based), for $nrows.

mixed

queryGrid(array summary, array params, boolen echo)

Return the result of the query to jqGrid.

string

exportToExcel(array summary, array params, array colmodel, boolean echo, string filename)

Export the recordset to excel xml file.

void

setPdfOptions(array apdf)

Set options for PDF export.

protected null

rs2pdf(object rs, pdf created, array colmodel, mixed pdf, mixed summary)

Convert a recordeset to pdf object

exportToPdf(array summary, array params, array colmodel, string filename)

Export the recordset to pdf file.

string

exportToCsv(array summary, array params, array colmodel, boolean echo, string filename, string sep, string sepreplace)

Public method to export a grid data to csv data.

void

querySubGrid(array params, boolean echo)

Return the result of the query for the simple subgrid The format depend of dataType variable

protected string

rs2excel(pdo recordset, array colmodel, boolean echo, string filename, array summary, mixed rs)

From a given recordset returns excel xml file.

void

addUserData(array adata)

Add a custom data to the grid footer row if it is enabled.

Field Detail

hgGrid.php at line 261

ExportCommand

public string $ExportCommand = ""

Set the sql command for excel export. If not set a _setSQL function is used to set a sql for export

See Also:
_setSQL

hgGrid.php at line 271

SubgridCommand

public string $SubgridCommand = ""

Set a sql command used for the simple subgrid


hgGrid.php at line 343

cacheCount

public boolean $cacheCount = false


hgGrid.php at line 326

customClass

public mixed $customClass = false

Custom call can be used again with custom function customFunc. We can call this using static defined functions in class customClass::customFunc - i.e $grid->customClass = Custom, $grid->customFunc = myfunc or $grid->customClass = new Custom(), $grid->customFunc = myfunc


hgGrid.php at line 327

customError

public mixed $customError = null

hgGrid.php at line 318

customFunc

public function $customFunc = null

Custom function which can be called to modify the grid output. Parameters passed to this function are the response object and the db connection


hgGrid.php at line 215

dataType

public string the $dataType = "xml"

The output format for the grid. Can be json or xml


hgGrid.php at line 234

datearray

public array $datearray = array()

Store the names which are dates. The name should correspond of the name in colModel. Used to perform the conversion from userdate and dbdate


hgGrid.php at line 144

debug

public boolean $debug = false

Enable disable debuging


hgGrid.php at line 220

encoding

public string $encoding = "utf-8"

Default enconding passed to the browser


hgGrid.php at line 184

errorMessage

public string $errorMessage = ''

Last error message from the server


hgGrid.php at line 266

gSQLMaxRows

public integer $gSQLMaxRows = 1000

Maximum number of rows to be exported for the excel export


hgGrid.php at line 253

higridSC

public string $higridSC = ""

In case if no table is set, this holds the sql command for retrieving the data from the db to the grid


hgGrid.php at line 228

jsonencode

public boolean $jsonencode = true

If set to true uses the PHP json_encode if available. If this is set to false a custom encode function in jqGrid is used. Also use this to false if the encoding of your database is not utf-8

Deprecated:
this not needed anymore also the related option is $encoding

hgGrid.php at line 150

logtofile

public boolean $logtofile = true

Determines if the log should be written to file or echoed. Ih set to created is a file HiGrid.log in the directory where the script is


hgGrid.php at line 247

mongofields

public array $mongofields = array()

Array which set which fields should be selected in case of mongodb. If the array is empty all fields will be selected from the collection.


hgGrid.php at line 241

mongointegers

public array $mongointegers = array()

Store the names for the int fields when database is MongoDB. Used to perform right serach in MongoDB. The array should contain the right names as listed into the collection


hgGrid.php at line 350

oper

public mixed $oper

hgGrid.php at line 338

optimizeSearch

public boolean $optimizeSearch = false

Optimizes the search SQL when used in MySQL with big data sets. Use this option carefully on complex SQL


hgGrid.php at line 349

performcount

public boolean $performcount = true

Internal set in queryGrid if we should use count query in order to set the grid output


hgGrid.php at line 306

readFromXML

public boolean $readFromXML = false

Obtain the SQL qurery from XML file. In this case the higridSC should be set as xmlfile.sqlid. The xmlfile is the name of xml file where we store the sql commands, sqlid is the id of the required sql. The simple xml file can look like this < ?xml version="1.0" encoding="UTF-8"?> Select * From users Where Id = ? Select Count(Id) From users Where Email = ? AND Password = ? Important note: The class first look for readFromXML, then for selectCommand and last for a table.


hgGrid.php at line 179

showError

public boolean $showError = false

If set to true all errors from the server are shown in the client in a dialog. Curretly work only for grid and form edit.


hgGrid.php at line 276

table

public string $table = ""

set a table to display a data to the grid


hgGrid.php at line 54

version

public string $version = '2.1'

Get te current version


hgGrid.php at line 332

xmlCDATA

public boolean $xmlCDATA = false

Defines if the xml otput should be enclosed in CDATA when xml output is enabled


Constructor Detail

hgGrid.php at line 356

__construct

public void __construct(mixed db, str odbctype, resource -)

Constructor

Parameters:
- - $db the database connection passed to the constructor

Method Detail

hgGrid.php at line 128

logQuery

public void logQuery(string sql, array data, array types, mixed input, mixed fld, str primary)

Log query


hgGrid.php at line 155

debugout

public void debugout()

Prints all executed SQL queries to file or console

See Also:
$logtofile

hgGrid.php at line 189

sendErrorHeader

public void sendErrorHeader()

Function to simulate 500 Internal error so that it sends the error to the client. It is activated only if $showError is true.


hgGrid.php at line 381

parseSql

protected string parseSql(string sqlElement, array params, bool bind)

Prepares a $sqlElement and binds a parameters $params Return prepared sql statement

Parameters:
sqlElement - sql to be prepared
params - - parameters passed to the sql

hgGrid.php at line 399

execute

protected boolean execute(string sqlId, array params, resource sql, boolean limit, integer nrows, integer offset, str order, str sort)

Executes a prepared sql statement. Also if limit is set to true is used to return limited set of records Return true on success

Parameters:
sqlId - - sql to pe executed
params - - array of values which are passed as parameters to the sql
sql - - pointer to the constructed sql
limit - - if set to true we use a pagging mechanizm
nrows - - number of rows to return
offset - - the offset from which the nrows should be returned

hgGrid.php at line 441

getSqlElement

protected mixed getSqlElement(string sqlId)

Read a xml file and the higridSC and return the sql string Return string if the query is found false if not.

Parameters:
sqlId - the string of type xmlfile.sqlId

hgGrid.php at line 520

queryForObject

protected object queryForObject(string sqlId, array params, boolean fetchAll)

Return the object from the query

Parameters:
sqlId - the sql to be queried
params - - parameter values passed to the sql
fetchAll - - if set to true fetch all records

hgGrid.php at line 537

getStringForGroup

protected array getStringForGroup(object group, array prm)

Recursivley build the sql query from a json object

Parameters:
group - the object to parse
prm - parameters array
Returns:
- first element is the where clause secon is the array of values to pass

hgGrid.php at line 675

buildSearch

public mixed buildSearch(string filter, string otype)

Build a search string from filter string posted from the grid Usually use this functio separatley

Returns:
- string or array depending on $otype param

hgGrid.php at line 721

getUserDate

public string getUserDate()

Return the current date format used from the client


hgGrid.php at line 729

setUserDate

public void setUserDate(string newformat)

Set a new user date format using PHP convensions

Parameters:
newformat - - the new format

hgGrid.php at line 737

getUserTime

public string getUserTime()

Return the current datetime format used from the client


hgGrid.php at line 745

setUserTime

public void setUserTime(string newformat)

Set a new user datetime format using PHP convensions

Parameters:
newformat - - the new format

hgGrid.php at line 753

getDbDate

public string getDbDate()

Return the current date format used in the undelayed database


hgGrid.php at line 761

setDbDate

public void setDbDate(string newformat)

Set a new database date format using PHP convensions

Parameters:
newformat - - the new database format

hgGrid.php at line 769

getDbTime

public string getDbTime()

Return the current datetime format used in the undelayed database


hgGrid.php at line 777

setDbTime

public void setDbTime(string newformat)

Set a new database datetime format using PHP convensions

Parameters:
newformat - - the new database format

hgGrid.php at line 787

getGridParams

public array getGridParams()

Return the associative array which contain the parameters that are sended from the grid to request, search, update delete data.


hgGrid.php at line 797

setGridParams

public void setGridParams(array _aparams)

Set a grid parameters to identify the action from the grid Note that these should be set in the grid - i.e the parameters from the grid should equal to the GridParams.

Parameters:
_aparams - set new parameter.

hgGrid.php at line 818

selectLimit

public object selectLimit(string limsql, integer is, array array, int nrows, int offset, mixed params, str order, str sort)

Will select, getting rows from $offset (1-based), for $nrows. This simulates the MySQL "select * from table limit $offset,$nrows" , and the PostgreSQL "select * from table limit $nrows offset $offset". Note that MySQL and PostgreSQL parameter ordering is the opposite of the other. eg. Also supports Microsoft SQL Server SelectLimit('select * from table',3); will return rows 1 to 3 (1-based) SelectLimit('select * from table',3,2); will return rows 3 to 5 (1-based) Return object containing the limited record set

Parameters:
limsql - - optional sql clause
is - the number of rows to get
is - the row to start calculations from (1-based)
array - of bind variables

hgGrid.php at line 844

queryGrid

public mixed queryGrid(array summary, array params, boolen echo)

Return the result of the query to jqGrid. Support searching

Parameters:
summary - - set which columns should be sumarized in order to be displayed to the grid By default this parameter uses SQL SUM function: array("colmodelname"=>"sqlname"); It can be set to use the other one this way array("colmodelname"=>array("sqlname"=>"AVG")); By default the first field correspond to the name of colModel the second to the database name
params - - parameter values passed to the sql
echo - if set to false return the records as object, otherwiese json encoded or xml string depending on the dataType variable

hgGrid.php at line 1015

exportToExcel

public string exportToExcel(array summary, array params, array colmodel, boolean echo, string filename)

Export the recordset to excel xml file. Can use the ExportCommand. If this command is not set uses _setSQL to set the query. The number of rows exported is limited from gSQLMaxRows variable

See Also:
_setSQL
Parameters:
summary - - set which columns should be sumarized in order to be displayed to the grid By default this parameter uses SQL SUM function: array("colmodelname"=>"sqlname"); It can be set to use the other one this way array("colmodelname"=>array("sqlname"=>"AVG")); By default the first field correspond to the name of colModel the second to the database name
params - parameter values passed to the sql array(value)
colmodel - - different description for the headers - see rs2excel
echo - determines if the result should be returned or echoed
filename - the filename to which the sheet can be saved in case if $echo is true

hgGrid.php at line 1112

setPdfOptions

public void setPdfOptions(array apdf)

Set options for PDF export.


hgGrid.php at line 1127

rs2pdf

protected null rs2pdf(object rs, pdf created, array colmodel, mixed pdf, mixed summary)

Convert a recordeset to pdf object

Parameters:
rs - the recorde set object from the query
created - object $pdf
colmodel - can be either manually created array see rs2excel or genereted from setColModel methd.

hgGrid.php at line 1353

exportToPdf

public exportToPdf(array summary, array params, array colmodel, string filename)

Export the recordset to pdf file. Can use the ExportCommand. If this command is not set uses _setSQL to set the query. The number of rows exported is limited from gSQLMaxRows variable

See Also:
_setSQL
Parameters:
summary - - set which columns should be sumarized in order to be displayed to the grid By default this parameter uses SQL SUM function: array("colmodelname"=>"sqlname"); It can be set to use the other one this way array("colmodelname"=>array("sqlname"=>"AVG")); By default the first field correspond to the name of colModel the second to the database name
params - parameter values passed to the sql array(value)
colmodel - - different description for the headers - see rs2excel
filename - the filename to which the sheet can be saved in case if $echo is true

hgGrid.php at line 1610

exportToCsv

public string exportToCsv(array summary, array params, array colmodel, boolean echo, string filename, string sep, string sepreplace)

Public method to export a grid data to csv data. Can use the ExportCommand. If this command is not set uses _setSQL to set the query. The number of rows exported is limited from gSQLMaxRows variable

See Also:
_setSQL
rs2excel
Parameters:
summary - - set which columns should be sumarized in order to be displayed to the grid By default this parameter uses SQL SUM function: array("colmodelname"=>"sqlname"); It can be set to use the other one this way array("colmodelname"=>array("sqlname"=>"AVG")); By default the first field correspond to the name of colModel the second to the database name
params - parameter values passed to the sql array(value)
colmodel - - different description for the headers
echo - determines if the result should be returned or echoed
filename - the filename to which the sheet can be saved in case if $echo is true
sep - - the separator for the csv data
sepreplace - - with what to replace the separator if in data

hgGrid.php at line 1630

querySubGrid

public void querySubGrid(array params, boolean echo)

Return the result of the query for the simple subgrid The format depend of dataType variable

Parameters:
params - parameters passed to the query
echo - if set to false return object containing the data

hgGrid.php at line 1703

rs2excel

protected string rs2excel(pdo recordset, array colmodel, boolean echo, string filename, array summary, mixed rs)

From a given recordset returns excel xml file. If the summary array is defined add summary formula at last row. Return well formated xml excel string

Parameters:
recordset - $rs recordset from pdo execute command
colmodel - diffrent descriptions for the headars, width, hidden cols This array is actually a colModel array in jqGrid. The array can look like Array( [0]=>Array("label"=>"Some label", "width"=>100, "hidden"=>true, "name"=>"client_id", "formatter"=>"select", editoptions=>...), [1]=>Array("label"=>"Other label", "width"=>80, "hidden"=>false, "name"=>"date",... ), ... )
echo - determines if the result should be send to browser or returned as string
filename - filename to which file can be saved
summary - - set which columns should be sumarized in order to be displayed to the grid By default this parameter uses SQL SUM function: array("colmodelname"=>"sqlname"); It can be set to use the other one this way array("colmodelname"=>array("sqlname"=>"AVG")); By default the first field correspond to the name of colModel the second to the database name

hgGrid.php at line 1892

addUserData

public void addUserData(array adata)

Add a custom data to the grid footer row if it is enabled. Also can be used to transport additional data in userdata array to be used later at client side. The syntax is $grid->addUserData(array("Name1"=>"Data1",...)); The method is executed after the sumarry rows are executed, so it can overwrite some summary data which is palced on the footer.


higrid.net