Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formating Results in Grid

Status
Not open for further replies.

saw15

Technical User
Jan 24, 2001
468
US
Using SQL Server 2000 and VI, I am using a recordset and grid to pull some data back from the database.

Currently the data is coming back with no format, for 1,500 its showing 1500.

Where can I set the formatting? I would assume that its somewhere in the runtime text, but where?

function _initGrid1()
{
Grid1.pageSize = 0;
Grid1.setDataSource(GetClaimStatus);
Grid1.tableAttributes = ' cellpadding=2 cellspacing=0 bordercolor=#cccccc bgcolor=Gray border=1 cols=2 rules=ALL WIDTH=304';
Grid1.headerAttributes = ' bgcolor=#003468 align=Left';
Grid1.headerWidth[0] = ' WIDTH=68';
Grid1.headerWidth[1] = ' WIDTH=68';
Grid1.headerFormat = '<Font face=&quot;Arial&quot; size=4 color=White> <b>';
Grid1.colHeader[0] = '\'Claim Status\'';
Grid1.colHeader[1] = '\'Total Claims\'';
Grid1.rowAttributes[0] = ' bgcolor = White align=Left bordercolor=#cccccc';
Grid1.rowAttributes[1] = ' bgcolor = Silver align=Left bordercolor=#cccccc';
Grid1.rowFormat[0] = ' <Font face=&quot;Arial&quot; size=2 color=Black >';
Grid1.colAttributes[0] = ' WIDTH=68';
Grid1.colFormat[0] = '<Font Size=2 Face=&quot;Arial&quot; Color=Black >';
Grid1.colData[0] = 'GetClaimStatus.fields.getValue(\'Claim Status\')';
Grid1.colAttributes[1] = ' WIDTH=68';
Grid1.colFormat[1] = '<Font Size=2 Face=&quot;Arial&quot; Color=Black >';
Grid1.colData[1] = 'GetClaimStatus.fields.getValue(\'Total Claims\')';
}

Help is appreciated, thanks.
 
You could do the formatting in the SQL clause (assuming that you do not want to update the recordset).

Or, in the grid properties dialog, just enter a format function in the required columns:
=gridFormatNumber([ColumnName])

now JavaScript does not have any built-in formatting functions, not even a 'sprint' function. (But it does have regular expressions.)
However, VBScript does have a (rather simplistic) format function (FormatNumber) that uses the international settings (control panel) of the Server to provide the correct comma and full-stop and negative sign placement.

Now, the grid expects a JavaScript OR a user defined function after the = sign in a grid column. If you just use the VBScript function, it will error.

So add, in your Server-Side VB Script block, the appropriate function:

Function gridFormatNumber(i_nNumber)
/* format the number with 2 decimal places */
gridFormatNumber = FormatNumber(i_nNumber,2)
End Function

And this is then referenced in the grid column.

Simple really!
(Content Management)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top