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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying Page Nos. in Grid DTC

Status
Not open for further replies.

mnongkhlaw

Programmer
Feb 22, 2002
62
0
0
IN
Hi,

I want my page-enabled Grid DTC to show Pages like
"Page 1 of 10" rather than "1/10". What needs to be set for this to happen?

Mark
(mark@shillong.meg.nic.in)
 
You will need to adjust the code in _ScriptLibrary/DATAGRID.ASP

In the Display method (function _DG_display(bReturnText)
), find this block:

if (this.hasPageNumber)
{
strHTML += '<TD align=right valign=middle>';
strHTML += '<FONT size=2><NOBR>' + String(curPage+1) + ' / ' + parseInt(nPages) + '</NOBR></FONT>';
strHTML += '</TD>\n';
}
strHTML += '</TR></TABLE>\n';

Amend the bold line with the required format.

A better method would be to set a Template string, that would allow the datagrid to change formatting in a more flexible manner:
1. Add a property to the DataGrid.asp, (here called strPageFmt).

function _DataGrid(strName,objParent)
{
// public members
this.id = strName;
this.strPageFmt = &quot;%page% of %pages%&quot;;

{1.1 OR have an array of standard formats}

2. Adjust the code as listed above to replace %page% with the String(curPage+1) value, and the %pages% with the parseInt(nPages) value.
var strPage = &quot;&quot;;
strPage = this.strPageFmt.replace(/%page%/ig, String(curPage+1));
strPage = strPage.replace(/%pages%/ig, parseInt(nPages))
strHTML += '<FONT size=2><NOBR>' + strPage + '</NOBR></FONT>';

(or something like that! (first parameter is a regular expression, and the % may need to be escaped))

3. In your page code (thispage_onenter), set the required format string:

grdMyGrid.strPageFmt = &quot;Now Showing <b>%page%</b> of %pages%&quot;.

VI will NOT pop-up this new property, but it should work.

NOTE: unless this format string is set on every page refresh, it will revert back to the default format that you set in step 1 above. Remembering these settings is what the preserveState/restoreState methods are meant to achieve - so see if you can figure out the required code!

Exercise: See if you can create a list of page links too. So grid pages 1 to 10 (for example) are listed as links, rather than just the Next/Prev buttons.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top