Assistance Required for Stimulsoft Report Rendering Issue

Stimulsoft Reports.JS discussion
Post Reply
m.nasser
Posts: 5
Joined: Thu Jan 04, 2024 5:38 pm

Assistance Required for Stimulsoft Report Rendering Issue

Post by m.nasser »

Dear Stimulsoft Support Team,

I hope this email finds you well. My name is Mahmoud, and I am writing to seek assistance with a challenging issue I've encountered while working with Stimulsoft.

Issue Description:
I am currently working on a project where I dynamically update the dataset for a Stimulsoft report and attempt to render the report using the Stimulsoft viewer in my application. However, despite my best efforts, I have not been successful in achieving the expected behavior.

Steps Taken:

- I am dynamically creating a new DataSet for each page of the report.
- I have cloned the original report for each page and created a DataTable (PageTable_${i}) with the appropriate columns and rows.
- I update the dataSourceName property of the Tableds component on each page with the corresponding DataTable name.
- Finally, I render the original report with all the modified pages using the renderHtml function.

Observations:

- The dataset structure seems correct, and the DataTables are being created successfully.
- The dataSourceName property of the Tableds component is being updated with the corresponding DataTable name.

Problem Faced:
Despite the aforementioned steps, the Stimulsoft viewer does not seem to reflect the changes in the dataset. The report renders with the original data, and the modifications made to the dataset do not take effect.

--------------------------------

// Create a new DataSet
var mainDataSet = new Stimulsoft.System.Data.DataSet();

data.pages.forEach((page, i) => {
// Clone the original report for each page
let clonedPage = targetPage.clone();

// Prepare the data for the current page
let pageTable = this.prepareExternalDeliveryPageTable(printType, page.rows, printSubject);

// Create a DataTable for each page
var pageDataTable = new Stimulsoft.System.Data.DataTable(`PageTable_${i}`);

// Assuming pageTable is an array of objects
if (pageTable.length > 0) {
// Add columns based on the first row (assumed to have the column names)
Object.keys(pageTable[0]).forEach(columnName => {
pageDataTable.columns.add(new Stimulsoft.System.Data.DataColumn(columnName));
});

// Add rows to the DataTable
pageTable.forEach(row => {
var newRow = pageDataTable.newRow();
Object.keys(row).forEach(columnName => {
newRow.setValue(columnName, row[columnName]);
});
pageDataTable.rows.add(newRow);
});

// Add the DataTable to the DataSet
mainDataSet.tables.add(pageDataTable);

// Get the Tableds component directly from the cloned page
var tableComponent = clonedPage.components.getByName("Tableds");

if (tableComponent) {
// Update the table component to reflect the changes in the dataset
tableComponent.dataSourceName = pageDataTable.tableName;
}
}

// Add the modified page to the original report
originalReport.pages.add(clonedPage);
});

// Render the original report with all modified pages
await originalReport.renderAsync(() => {
viewer.renderHtml("viewerContent");
});

-----------------------------------


Request for Assistance:
I kindly request your guidance in resolving this issue. If there are any specific methods or considerations I may be overlooking, or if there's a preferred way to dynamically update the dataset and reflect the changes in the viewer, your expertise would be greatly appreciated.

Additional Information:

Stimulsoft Product Version: Stimulsoft JS 2023.3.3
Programming Language: JavaScript, TypeScript
Framework or Platform: Angular

Thank you for your time and assistance. I look forward to your guidance on resolving this matter.

Best regards,

Mahmoud Nasser
m.nasser@t2.sa
Attachments
Report (2).mrt
(65.47 KiB) Downloaded 93 times
Lech Kulikowski
Posts: 6271
Joined: Tue Mar 20, 2018 5:34 am

Re: Assistance Required for Stimulsoft Report Rendering Issue

Post by Lech Kulikowski »

Hello,

In that case, we recommend use report with one page, render it with different datasets, and then merge all rendered reports(pages) in one.

Thank you.
m.nasser
Posts: 5
Joined: Thu Jan 04, 2024 5:38 pm

Re: Assistance Required for Stimulsoft Report Rendering Issue

Post by m.nasser »

Hello Lech,

How can I do this? Can you provide me with a reference or code or anything?

I'm trying with this code:


// Create a new Merged Report to hold all modified pages
var mergedReport = originalReport // new Stimulsoft.Report.StiReport();
//mergedReport.pages.list.splice(0, 1); // Clear all pages after cloning

data.pages.forEach((page, i) => {
// Clone the original report for each page
let clonedPage = targetPage.clone();

// Prepare the data for the current page
let pageTable = this.preparePageTable(printType, page.rows, printSubject);

// Create a DataTable for each page
var pageDataTable = new Stimulsoft.System.Data.DataTable(`PageTable_${i}`);

// Assuming pageTable is an array of objects
if (pageTable.length > 0) {
// Add columns based on the first row (assumed to have the column names)
Object.keys(pageTable[0]).forEach(columnName => {
pageDataTable.columns.add(new Stimulsoft.System.Data.DataColumn(columnName));
});

// Add rows to the DataTable
pageTable.forEach(row => {
var newRow = pageDataTable.newRow();
Object.keys(row).forEach(columnName => {
newRow.setValue(columnName, row[columnName]);
});
pageDataTable.rows.add(newRow);
});

let dsName = `ds_${i}`;
// Create a new DataSet for each page
var ds = new Stimulsoft.System.Data.DataSet(dsName, dsName);
ds.tables.add(pageDataTable);

// Get the Tableds component directly from the cloned page
var tableComponent = clonedPage.components.getByName('Tableds_AllInOne');

if (tableComponent) {
// Update only the dataSourceName of the existing component
tableComponent.dataSourceName = dsName //pageDataTable.tableName;
}

// Add the modified page to the merged report
mergedReport.pages.add(clonedPage);

mergedReport.regData(dsName, dsName, ds);
}
});

console.log('################################');

mergedReport.dictionary.synchronize();
viewer.report = mergedReport;

await mergedReport.renderAsync(() => {
viewer.renderHtml("viewerContent");
}, (error) => {
console.error("Render Error:", error);
});

-----------------

But when I have multiple tables, no data is showing. I think the problem is in the 'mergedReport.regData(dsName, dsName, ds);' – maybe it's not accepting multiple datasets, because a single page is working fine
Please your help
Lech Kulikowski
Posts: 6271
Joined: Tue Mar 20, 2018 5:34 am

Re: Assistance Required for Stimulsoft Report Rendering Issue

Post by Lech Kulikowski »

Hello,

Please check the discussion at the following topic:
viewtopic.php?f=27&t=56842

Thank you.
Post Reply