Skip to content

Commit c51b80d

Browse files
committed
documentation(EJ2-67661): UG document to save and load report using database.
1 parent 605cba5 commit c51b80d

8 files changed

Lines changed: 95 additions & 158 deletions

File tree

Javascript/README.md

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,18 @@
1-
# How to bind MSSQL database to pivot table
1+
# How to bind MSSQL database to pivot table Save & Load Actions
22

3-
## Introduction
3+
A quick start project that shows how to save and load reports from a SQL Server database and load them into the Syncfusion Pivot Table at run time. This repository includes a ASP.NET Core Web App Controller ([MyWebService](../MyWebService/)) for saving and loading reports from a SQL server database, as well as a quick start samples in the JavaScript platform that displays the loaded report in a Syncfusion Pivot Table.
44

5-
This repository contains client-side Javascript sample for syncfusion pivot table save & load.
5+
## Project prerequisites
66

7-
## Prerequesties software
7+
Before beginning work on the server and client projects, ensure the following software to be installed in the machine.
88

9-
Make sure that you have the following requirements in your machine before starting to work on the client projects.
9+
* [git](https://git-scm.com/downloads)
10+
* [Node.js](https://nodejs.org/en/)
11+
* [Visual Studio Code](https://code.visualstudio.com/)
12+
* [Visual Studio 2022](https://visualstudio.microsoft.com/downloads/ ) and [.NET Core SDK 6.0](https://dotnet.microsoft.com/en-us/download/dotnet/6.0) or later installed on your machine
1013

11-
* git
12-
* Visual Studio Code (Optional)
13-
* Visual Studio 2022 (Optional)
14+
## How to run this application?
1415

15-
## Guide to download
16+
* To run this application, clone the [Save-and-load-report-from-SQL-database-to-pivot-table](https://github.com/SyncfusionExamples/Save-and-load-report-from-SQL-database-to-pivot-table) repository and then open **MyWebService** in Visual Studio 2022. Simply build and run your project in IIS Express, and it will host and display the URL 'https://localhost:44313'.
1617

17-
* To run this application, you need to clone the `Save-and-load-report-from-SQL-database-to-pivot-table` repository and then navigate to the path where it has been stored in your system.
18-
19-
* To do so, open the command prompt and run the below command.
20-
21-
```
22-
git clone https://github.com/SyncfusionExamples/Save-and-load-report-from-SQL-database-to-pivot-table
23-
24-
```
25-
26-
## Guide to Run sample
27-
28-
Once done with downloading, follows the steps one after the other.
29-
30-
* Run **MyWebService** (Server-side) Core Api application in Visual Studio to get the API link.
31-
32-
* Now open the Javascript pivot-table sample and Open the `index.html` file in browser page.
18+
* Now open JavaScript sample in Visual Studio Code. Initialize the Pivot Table, map the hosted URL,create a pivot report, and finally, open the **index.html** file in your browser to run your project.

Javascript/pivot-table/index.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ var pivotTableObj = new ej.pivotview.PivotView({
2828
report: JSON.stringify(report),
2929
}),
3030
})
31-
.then(function (res) {
32-
return res.json();
33-
})
3431
.then(function (response) {
3532
pivotTableObj.fetchReport();
3633
});
@@ -49,9 +46,7 @@ var pivotTableObj = new ej.pivotview.PivotView({
4946
})
5047
.then(function (response) {
5148
updateReport(
52-
response.ReportNameList !== ""
53-
? response.ReportNameList.split("__")
54-
: []
49+
response.length > 0 ? response : []
5550
);
5651
});
5752
},
@@ -68,8 +63,8 @@ var pivotTableObj = new ej.pivotview.PivotView({
6863
return res.json();
6964
})
7065
.then(function (response) {
71-
if (response.Report) {
72-
var report = JSON.parse(response.Report);
66+
if (response) {
67+
var report = JSON.parse(response);
7368
report.dataSourceSettings.dataSource =
7469
pivotTableObj.dataSourceSettings.dataSource;
7570
pivotTableObj.dataSourceSettings = report.dataSourceSettings;
@@ -85,9 +80,6 @@ var pivotTableObj = new ej.pivotview.PivotView({
8580
},
8681
body: JSON.stringify({ reportName: args.reportName }),
8782
})
88-
.then(function (res) {
89-
return res.json();
90-
})
9183
.then(function (response) {
9284
pivotTableObj.fetchReport();
9385
});
@@ -104,9 +96,6 @@ var pivotTableObj = new ej.pivotview.PivotView({
10496
renameReport: args.rename,
10597
}),
10698
})
107-
.then(function (res) {
108-
return res.json();
109-
})
11099
.then(function (response) {
111100
pivotTableObj.fetchReport();
112101
});

MyWebService/Controllers/PivotController.cs

Lines changed: 43 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ public class PivotController : ControllerBase
99
{
1010
[HttpPost]
1111
[Route("Pivot/SaveReport")]
12-
public IActionResult SaveReport([FromBody] SaveReportDB reportDB)
12+
public void SaveReport([FromBody] SaveReportDB reportDB)
1313
{
14-
return Ok((SaveReportToDB(reportDB.ReportName, reportDB.Report)));
14+
SaveReportToDB(reportDB.ReportName, reportDB.Report);
1515
}
1616

1717
[HttpPost]
@@ -23,16 +23,16 @@ public IActionResult FetchReport()
2323

2424
[HttpPost]
2525
[Route("Pivot/RemoveReport")]
26-
public IActionResult RemoveReport([FromBody] ReportDB reportDB)
26+
public void RemoveReport([FromBody] ReportDB reportDB)
2727
{
28-
return Ok((RemoveReportFromDB(reportDB.ReportName)));
28+
RemoveReportFromDB(reportDB.ReportName);
2929
}
3030

3131
[HttpPost]
3232
[Route("Pivot/RenameReport")]
33-
public IActionResult RenameReport([FromBody] RenameReportDB reportDB)
33+
public void RenameReport([FromBody] RenameReportDB reportDB)
3434
{
35-
return Ok((RenameReportInDB(reportDB.ReportName, reportDB.RenameReport)));
35+
RenameReportInDB(reportDB.ReportName, reportDB.RenameReport);
3636
}
3737

3838
[HttpPost]
@@ -65,120 +65,100 @@ public class ErrorViewModel
6565
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
6666
}
6767

68-
public Dictionary<string, object> SaveReportToDB(string reportName, string report)
68+
public void SaveReportToDB(string reportName, string report)
6969
{
70-
string conSTR = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + Environment.CurrentDirectory
71-
+ @"\App_Data\Database1.mdf;Integrated Security=True";
70+
SqlConnection sqlConn = OpenConnection();
7271
bool isDuplicate = true;
73-
SqlConnection sqlConn = new SqlConnection(conSTR);
74-
sqlConn.Open();
7572
SqlCommand cmd1 = null;
7673
foreach (DataRow row in GetDataTable(sqlConn).Rows)
7774
{
78-
if ((row.ItemArray[0] as string).Equals(reportName))
75+
if ((row["ReportName"] as string).Equals(reportName))
7976
{
8077
isDuplicate = false;
81-
cmd1 = new SqlCommand("update ReportTable set Report=@Report where ReportName like @ReportName", sqlConn);
78+
cmd1 = new SqlCommand("UPDATE ReportTable set Report=@Report where ReportName like @ReportName", sqlConn);
8279
}
8380
}
8481
if (isDuplicate)
8582
{
86-
cmd1 = new SqlCommand("insert into ReportTable Values(@ReportName,@Report)", sqlConn);
83+
cmd1 = new SqlCommand("INSERT into ReportTable (ReportName,Report) Values(@ReportName,@Report)", sqlConn);
8784
}
8885
cmd1.Parameters.AddWithValue("@ReportName", reportName);
8986
cmd1.Parameters.AddWithValue("@Report", report.ToString());
9087
cmd1.ExecuteNonQuery();
9188
sqlConn.Close();
92-
Dictionary<string, object> dictionary = new Dictionary<string, object>();
93-
dictionary.Add("CurrentAction", "Save");
94-
return dictionary;
9589
}
9690

97-
public Dictionary<string, object> RemoveReportFromDB(string reportName)
91+
public void RemoveReportFromDB(string reportName)
9892
{
99-
string conSTR = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + Environment.CurrentDirectory
100-
+ @"\App_Data\Database1.mdf;Integrated Security=True";
101-
SqlConnection sqlConn = new SqlConnection(conSTR);
102-
sqlConn.Open();
93+
SqlConnection sqlConn = OpenConnection();
10394
SqlCommand cmd1 = null;
10495
foreach (DataRow row in GetDataTable(sqlConn).Rows)
10596
{
106-
if ((row.ItemArray[0] as string).Equals(reportName))
97+
if ((row["ReportName"] as string).Equals(reportName))
10798
{
10899
cmd1 = new SqlCommand("DELETE FROM ReportTable WHERE ReportName LIKE '%" + reportName + "%'", sqlConn);
100+
break;
109101
}
110102
}
111103
cmd1.ExecuteNonQuery();
112104
sqlConn.Close();
113-
Dictionary<string, object> dictionary = new Dictionary<string, object>();
114-
dictionary.Add("CurrentAction", "Remove");
115-
return dictionary;
116105
}
117106

118-
public Dictionary<string, object> RenameReportInDB(string reportName, string renameReport)
107+
public void RenameReportInDB(string reportName, string renameReport)
119108
{
120-
string conSTR = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + Environment.CurrentDirectory
121-
+ @"\App_Data\Database1.mdf;Integrated Security=True";
122-
SqlConnection sqlConn = new SqlConnection(conSTR);
123-
sqlConn.Open();
109+
SqlConnection sqlConn = OpenConnection();
124110
SqlCommand cmd1 = null;
125111
foreach (DataRow row in GetDataTable(sqlConn).Rows)
126112
{
127-
if ((row.ItemArray[0] as string).Equals(reportName))
113+
if ((row["ReportName"] as string).Equals(reportName))
128114
{
129-
cmd1 = new SqlCommand("update ReportTable set ReportName=@RenameReport where ReportName like '%" + reportName + "%'", sqlConn);
115+
cmd1 = new SqlCommand("UPDATE ReportTable set ReportName=@RenameReport where ReportName like '%" + reportName + "%'", sqlConn);
116+
break;
130117
}
131118
}
132119
cmd1.Parameters.AddWithValue("@RenameReport", renameReport);
133120
cmd1.ExecuteNonQuery();
134121
sqlConn.Close();
135-
Dictionary<string, object> dictionary = new Dictionary<string, object>();
136-
dictionary.Add("CurrentAction", "Rename");
137-
return dictionary;
138122
}
139123

140-
public Dictionary<string, object> FetchReportListFromDB()
124+
public List<string> FetchReportListFromDB()
141125
{
142-
string conSTR = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + Environment.CurrentDirectory
143-
+ @"\App_Data\Database1.mdf;Integrated Security=True";
144-
SqlConnection sqlConn = new SqlConnection(conSTR);
145-
sqlConn.Open();
146-
string reportNames = string.Empty, currentRptName = string.Empty;
147-
foreach (System.Data.DataRow row in GetDataTable(sqlConn).Rows)
126+
SqlConnection sqlConn = OpenConnection();
127+
List<string> reportNames = new List<string>();
128+
foreach (DataRow row in GetDataTable(sqlConn).Rows)
148129
{
149-
currentRptName = (row.ItemArray[0] as string);
150-
reportNames = reportNames == "" ? currentRptName : reportNames + "__" + currentRptName;
130+
if (!string.IsNullOrEmpty(row["ReportName"] as string))
131+
{
132+
reportNames.Add(row["ReportName"].ToString());
133+
}
151134
}
152135
sqlConn.Close();
153-
Dictionary<string, object> dictionary = new Dictionary<string, object>();
154-
dictionary.Add("ReportNameList", reportNames);
155-
dictionary.Add("CurrentAction", "Fetch");
156-
return dictionary;
136+
return reportNames;
157137
}
158138

159-
public Dictionary<string, object> LoadReportFromDB(string reportName)
139+
public string LoadReportFromDB(string reportName)
160140
{
161-
string conSTR = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + Environment.CurrentDirectory
162-
+ @"\App_Data\Database1.mdf;Integrated Security=True";
163-
SqlConnection sqlConn = new SqlConnection(conSTR);
164-
sqlConn.Open();
165-
Dictionary<string, object> dictionary = new Dictionary<string, object>();
166-
string currentRptName = string.Empty;
141+
SqlConnection sqlConn = OpenConnection();
167142
string report = string.Empty;
168143
foreach (DataRow row in GetDataTable(sqlConn).Rows)
169144
{
170-
currentRptName = row.ItemArray[0] as string;
171-
if (currentRptName.Equals(reportName))
145+
if ((row["ReportName"] as string).Equals(reportName))
172146
{
173-
report = row.ItemArray[1] as string;
174-
dictionary.Add("ReportName", currentRptName);
175-
dictionary.Add("Report", report);
176-
dictionary.Add("CurrentAction", "Load");
147+
report = (string)row["Report"];
177148
break;
178149
}
179150
}
180151
sqlConn.Close();
181-
return dictionary;
152+
return report;
153+
}
154+
155+
private SqlConnection OpenConnection()
156+
{
157+
string connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + Environment.CurrentDirectory
158+
+ @"\App_Data\Database1.mdf;Integrated Security=True";
159+
SqlConnection sqlConn = new SqlConnection(connectionString);
160+
sqlConn.Open();
161+
return sqlConn;
182162
}
183163

184164
private DataTable GetDataTable(SqlConnection sqlConn)

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Save-and-load-report-from-SQL-database-to-pivot-table
2-
Save and load report from SQL Server Database to a Pivot Table
1+
# Save and load report from SQL database to a Pivot Table
32

4-
A quick start project for connecting a SQL server database to a Syncfusion Pivot Table Save & Load Actions. This repository includes a ASP.NET Core Web App Controller (MyWebService) for performing Save & Load Actions from a SQL server database, as well as a quick start samples in the TypeScript, JavaScript, Angular, React, VUE, ASP.NET Core and MVC platforms that display the perform Save & Load Actions in a Syncfusion Pivot Table.
3+
A quick start project that shows how to save and load reports from a SQL Server database and load them into the Syncfusion Pivot Table at run time. This repository includes a ASP.NET Core Web App Controller ([MyWebService](./MyWebService/)) for saving and loading reports from a SQL server database, as well as a quick start samples in the [TypeScript](./Typescript/), [JavaScript](./Javascript/), [Angular](./Angular/), [React](./React/), [VUE](./VUE/), ASP.NET [Core](./Core/) and [MVC](./MVC/) platforms that displays the loaded report in a Syncfusion Pivot Table.

React/README.md

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,29 @@
1-
# How to bind MSSQL database to pivot table
1+
# How to bind MSSQL database to pivot table Save & Load Actions
22

3-
## Introduction
3+
A quick start project that shows how to save and load reports from a SQL Server database and load them into the Syncfusion Pivot Table at run time. This repository includes a ASP.NET Core Web App Controller ([MyWebService](../MyWebService/)) for saving and loading reports from a SQL server database, as well as a quick start samples in the React platform that displays the loaded report in a Syncfusion Pivot Table.
44

5-
This repository contains client-side React sample for syncfusion pivot table save & load.
5+
## Project prerequisites
66

7-
## Prerequesties software
7+
Before beginning work on the server and client projects, ensure the following software to be installed in the machine.
88

9-
Make sure that you have the following requirements in your machine before starting to work on the client projects.
9+
* [git](https://git-scm.com/downloads)
10+
* [Node.js](https://nodejs.org/en/)
11+
* [React](https://reactjs.org/)
12+
* [Visual Studio Code](https://code.visualstudio.com/)
13+
* [Visual Studio 2022](https://visualstudio.microsoft.com/downloads/ ) and [.NET Core SDK 6.0](https://dotnet.microsoft.com/en-us/download/dotnet/6.0) or later installed on your machine.
1014

11-
* git
12-
* React
13-
* Node Package Manager (NPM suggests versions above **14+**)
14-
* Visual Studio Code (Optional)
15-
* Visual Studio 2022 (Optional)
15+
## How to run this application?
1616

17-
## Guide to download
17+
* To run this application, clone the [Save-and-load-report-from-SQL-database-to-pivot-table](https://github.com/SyncfusionExamples/Save-and-load-report-from-SQL-database-to-pivot-table) repository and then open **MyWebService** in Visual Studio 2022. Simply build and run your project in IIS Express, and it will host and display the URL 'https://localhost:44313'.
1818

19-
* To run this application, you need to clone the `Save-and-load-report-from-SQL-database-to-pivot-table` repository and then navigate to the path where it has been stored in your system.
19+
* Now open React sample in Visual Studio Code and and install the necessary npm packages using the following command.
2020

21-
* To do so, open the command prompt and run the below command.
22-
23-
```
24-
git clone https://github.com/SyncfusionExamples/Save-and-load-report-from-SQL-database-to-pivot-table
25-
26-
```
27-
28-
## Guide to Run sample
29-
30-
Once done with downloading, follows the steps one after the other.
31-
32-
* Run **MyWebService** (Server-side) Core Api application in Visual Studio to get the API link.
33-
34-
* Now open React platform sample in Visual Studio Code and install the necessary npm packages using the following command line script.
3521
```sh
3622
npm install
3723
```
3824

39-
* Now run your project using the following command line script.
25+
* Initialize the Pivot Table, map the hosted URL, create a pivot report, and finally run your project using the following command to achieve the desired result.
26+
4027
```sh
4128
npm start
42-
```
29+
```

0 commit comments

Comments
 (0)