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
somehuman  
#1 Posted : Friday, October 16, 2015 1:56:23 PM(UTC)
somehuman

Rank: Newbie

Groups: Registered
Joined: 10/16/2015(UTC)
Posts: 2
United States

In my model I'm using a PostLoad Razor script to modify some columns after pulling the data from the database - this works great.

However, it messes up the sort order of the columns when they are displayed.

Is it possible to force a sort of a column in the UI after display via a Razor script? or to sort the data returned from the database after my script changes the data?

Thanks
somehuman
epf  
#2 Posted : Friday, October 16, 2015 2:15:26 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)
Well, I would say you can customize your DataTable sort,
check http://stackoverflow.com/questions/9107916/sorting-rows-in-a-data-table

In Seal, it would be:
DataView dv = model.ResultTable.DefaultView;
dv.Sort = "aColumn desc";
model.ResultTable; = dv.ToTable();

I hope it helps (but not tested !)
somehuman  
#3 Posted : Friday, October 16, 2015 5:29:26 PM(UTC)
somehuman

Rank: Newbie

Groups: Registered
Joined: 10/16/2015(UTC)
Posts: 2
United States

Good idea, but I'm getting the following error on the line: DataView dv = model.ResultTable.DefaultView;

Error in model 'model': Error when executing 'Post Load Script'.
Object reference not set to an instance of an object.

My postload script is the default with the only addition of the line above:
@using Seal.Model
@using System.Data
@{
ReportModel model = Model;
ReportExecutionLog log = model.Report;

//Final script executed to modify the model result tables after its generation
//Note that other assemblies can be used by saving the .dll in the Repository 'Assemblies' sub-folder...
log.LogMessage("Modifying result values with the 'Final Script'...");
ResultTable summaryTable = model.SummaryTable;
foreach (ResultPage page in model.Pages)
{
ResultTable dataTable = page.DataTable;
ResultTable pageTable = page.PageTable;

/* e.g to change the last line of the Data Tables
dataTable.Lines[dataTable.Lines.Count - 1][0].Value = "Maximum";
for (int i=0;i< dataTable.Lines[0].Length; i++)
{
string style = "background:orange;" + (i > 0 ? "text-align:right;" : "");
dataTable.Lines[dataTable.Lines.Count - 1][i].FinalCssStyle = style;
}
*/
}

DataView dv = model.ResultTable.DefaultView;
}
epf  
#4 Posted : Sunday, October 18, 2015 1:13:26 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)
I made a quick try on the sample report '01 Simple list':
Code:
	DataView dv = model.ResultTable.DefaultView;
	dv.Sort = "C3 desc";
	model.ResultTable = dv.ToTable();


and it works fine !

can you check that your error does not come from somewhere else (looks like result table is null) ?

Edited by user Sunday, October 18, 2015 1:14:02 PM(UTC)  | Reason: Not specified

Users browsing this topic
Guest (2)
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.