Page 1 of 2
Create filter variables programmatically
Posted: Thu Apr 14, 2016 1:05 pm
by felipemoreira
Hi.
I already know pass all data to report. Now, i need create filter variables programmatically (not fixed in the report) and use them to filter data before show report viewer to user.
Let's suppose i have a json file like data source with:
Code: Select all
{
"name" : "Jon,
"Age": 30
},
{
"name" : "Jon,
"Age": 31
}
And i need filter ages > 30, then show report to user.
How can i do that ?
Thanks.
Re: Create filter variables programmatically
Posted: Fri Apr 15, 2016 12:20 pm
by Alex K.
Hello,
Please try to use the following code:
Code: Select all
var band = report.getComponentByName("DataCategories");
band.filters.add(new Stimulsoft.Report.Components.StiFilter("ColumnName", Stimulsoft.Report.Components.StiFilterCondition.GreaterThan, "30", Stimulsoft.Report.Components.StiFilterDataType.Numeric));
Thank you.
Re: Create filter variables programmatically
Posted: Fri Apr 15, 2016 5:04 pm
by felipemoreira
Code: Select all
var report = new Stimulsoft.Report.StiReport();
report.loadFile("js/Names.mrt");
report.dictionary.databases.clear();
report.regData("teste", "teste", names);
var band = report.getComponentByName("DataCategories");
band.filters.add(new Stimulsoft.Report.Components.StiFilter("age",
Stimulsoft.Report.Components.StiFilterCondition.GreaterThan, "30", Stimulsoft.Report.Components.StiFilterDataType.Numeric));
var viewer = new Stimulsoft.Viewer.StiViewer(null, "StiViewer", false);
viewer.report = report;
viewer.renderHtml("report_designer");
My datasource json file:
Code: Select all
var names = {
"Names": [{
"name": "john",
"age" : 30
}, {
"name": "Abel",
"age" : 23
}, {
"name": "Joe",
"age" : 34
}, {
"name": "Joseph",
"age" : 30
}]
}
The report does not open. If i comment the lines about that treat the data filter, the report shows up with all data.
What's wrong ?
Thanks.
Re: Create filter variables programmatically
Posted: Fri Apr 15, 2016 5:21 pm
by felipemoreira
Follows attached report file to help resolve the problem resolution.
Re: Create filter variables programmatically
Posted: Mon Apr 18, 2016 6:45 pm
by Jan
Hello,
Please try to use following code:
Code: Select all
var band = report.getComponentByName("DataBand1");
var filter = new Stimulsoft.Report.Components.StiFilter();
filter.column = "age";
filter.condition = Stimulsoft.Report.Components.StiFilterCondition.GreaterThan;
filter.value1 = "30";
filter.dataType = Stimulsoft.Report.Components.StiFilterDataType.Numeric;
band.filters.add(filter);
Please contact us if you need any help!
Thank you.
Re: Create filter variables programmatically
Posted: Mon Apr 25, 2016 7:26 pm
by felipemoreira
This is my code to load report with filter (updated) :
Code: Select all
var report = new Stimulsoft.Report.StiReport();
report.loadFile("js/Names.mrt");
var band = report.getComponentByName("DataBand1");
var filter = new Stimulsoft.Report.Components.StiFilter();
filter.column = "age";
filter.condition = Stimulsoft.Report.Components.StiFilterCondition.GreaterThan;
filter.value1 = "30";
filter.dataType = Stimulsoft.Report.Components.StiFilterDataType.Numeric;
band.filters.add(filter);
report.regData("teste", "teste", names);
var viewer = new Stimulsoft.Viewer.StiViewer(null, "StiViewer", false);
viewer.report = report;
viewer.renderHtml("report_designer");
My datasource:
Code: Select all
var names = {
"Names": [{
"name": "john",
"age" : 30
}, {
"name": "Abel",
"age" : 23
}, {
"name": "Joe",
"age" : 34
}, {
"name": "Joseph",
"age" : 32
}]
}
And still does not work. It shows only a blank page. If i remove the filter part, works normally with full data.
Thanks.
Re: Create filter variables programmatically
Posted: Tue Apr 26, 2016 9:04 am
by HighAley
Hello.
Sorry, but we could not reproduce the issue on our current build.
Please, upgrade to the latest build (2016.1.9 from 2016.04.22).
Thank you.
Re: Create filter variables programmatically
Posted: Tue Apr 26, 2016 12:55 pm
by felipemoreira
Re: Create filter variables programmatically
Posted: Tue Apr 26, 2016 1:34 pm
by felipemoreira
Hi.
It works with 2016.04.22 build. Is stable ? Can i use in production ?
Re: Create filter variables programmatically
Posted: Wed Apr 27, 2016 12:06 pm
by HighAley
Hello.
We recommend you to use the latest build, because we make many important improvements each week.
Each our next build is much more stable than previous.
Thank you.