logo

Warning: The forum is now for consultation only. Please use GitHub Discussions to post any questions or comments.


Welcome Guest ! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
RamKumar  
#1 Posted : Friday, June 1, 2018 9:20:56 AM(UTC)
RamKumar

Rank: Newbie

Groups: Registered
Joined: 5/31/2018(UTC)
Posts: 1
India
Location: Hyderabad

I have designed a report and showing data into grid.
I want to setup a filter from which user can select TOP N, and based on that want to show records from Data grid.
Example. If user chooses 5, the datagrid should show only 5 records
epf  
#2 Posted : Friday, June 1, 2018 3:08:50 PM(UTC)
epf

Rank: Administration

Groups: Administrators
Joined: 12/20/2013(UTC)
Posts: 1,209
Switzerland

Thanks: 14 times
Was thanked: 206 time(s) in 199 post(s)
You can do that at least in 2 ways:
You have first to add an input parameter as done in sample '51-User Input', named 'Nb of Records='

1) Update the SELECT statement to add the TOP (works for SQLServer or Access)
Just a a task to do this with the following code
Code:
	ReportRestriction restriction = report.Models[0].GetRestrictionByName("Nb of Records=");
	if (restriction != null && restriction.DoubleValue > 0) 
	{
		report.Models[0].SqlSelect = string.Format("SELECT TOP {0}", restriction.DoubleValue);
	}


2) The other ways is to remove the extra rows from your result data table
In your model, edit the Post load Script with the following code:
Code:
	ReportRestriction restriction = model.GetRestrictionByName("Nb of Records=");
	if (restriction != null && restriction.DoubleValue > 0) {
		int i = table.Rows.Count - 1;
		while (i >= restriction.DoubleValue && i >= 0) {
			table.Rows.RemoveAt(i);
			i--; 
		}
	}


First method is the best for performances reason, you can do it in Oracle by adding 'rownum<xx' in the restrictionText.

In attachment is my sample based on the 51.
51-User input - Nb Of Records.srex (19kb) downloaded 5 time(s).
RamKumar  
#3 Posted : Tuesday, June 5, 2018 4:49:09 AM(UTC)
RamKumar

Rank: Newbie

Groups: Registered
Joined: 5/31/2018(UTC)
Posts: 1
India
Location: Hyderabad

Thank you.
Task is working as expected.
RamKumar  
#4 Posted : Friday, June 15, 2018 7:07:32 AM(UTC)
RamKumar

Rank: Newbie

Groups: Registered
Joined: 5/31/2018(UTC)
Posts: 1
India
Location: Hyderabad

Hi,
We used Task to provide TOP N records and it is working as expected. Now, how can we restrict user enter digits in "Nb of Records=" to 3?
It should accept upto number 999(3 digits), if user enters 1000 or more(4 digits) then it should not accept.

And when we set "Is required" option to "True", it is showing "*" on top of the title of that filter in Black color. Is there any way to change that * color from Black to Red?

Edited by user Friday, June 15, 2018 9:31:40 AM(UTC)  | Reason: Not specified

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.