Create filter variables programmatically

Stimulsoft Reports.JS discussion
felipemoreira
Posts: 38
Joined: Wed Mar 30, 2016 1:52 pm
Location: Brazil

Create filter variables programmatically

Post 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.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Create filter variables programmatically

Post 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.
felipemoreira
Posts: 38
Joined: Wed Mar 30, 2016 1:52 pm
Location: Brazil

Re: Create filter variables programmatically

Post 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.
felipemoreira
Posts: 38
Joined: Wed Mar 30, 2016 1:52 pm
Location: Brazil

Re: Create filter variables programmatically

Post by felipemoreira »

Follows attached report file to help resolve the problem resolution.
Attachments
Names.mrt
(1.7 KiB) Downloaded 199 times
Jan
Posts: 1265
Joined: Thu Feb 19, 2009 8:19 am

Re: Create filter variables programmatically

Post 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.
felipemoreira
Posts: 38
Joined: Wed Mar 30, 2016 1:52 pm
Location: Brazil

Re: Create filter variables programmatically

Post 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.
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Create filter variables programmatically

Post 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.
felipemoreira
Posts: 38
Joined: Wed Mar 30, 2016 1:52 pm
Location: Brazil

Re: Create filter variables programmatically

Post by felipemoreira »

Code: Select all

{"ReportVersion":"2016.1"}
Is this version ?
felipemoreira
Posts: 38
Joined: Wed Mar 30, 2016 1:52 pm
Location: Brazil

Re: Create filter variables programmatically

Post by felipemoreira »

Hi.

It works with 2016.04.22 build. Is stable ? Can i use in production ?
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Create filter variables programmatically

Post 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.
Post Reply