We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Use PivotGrid with view of sql entity

Hello
I need to example for add dates to PivotGrid with to view of sql Entity Framework or with to DataTable. 
When is the correct option? I can use PivotGrid1.(What) for this?

6 Replies

AA Arulraj A Syncfusion Team March 21, 2019 12:16 PM UTC

Hi Guadalupe, 

Thanks for contacting Syncfusion support. 

You can render PivotGrid with DataTable as datasource. Please follow the below steps. 

Step 1: 
 
Add the following class into the WebAPI controller file. 

Code Snippet:[c#] 
public class DbaseQuery 
{ 
public dynamic GetSQLResult(dynamic clientParam) 
{ 
string conSTR = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + AppDomain.CurrentDomain.BaseDirectory + @"App_Data\Database1.mdf;Integrated Security=True";//SQL database connection string 
string xquery = "SELECT * FROM table1"; 
SqlConnection sqlConn = new SqlConnection(conSTR); 
sqlConn.Open(); 
SqlCommand cmd = new SqlCommand(xquery, sqlConn); 
SqlDataAdapter da = new SqlDataAdapter(cmd); 
DataTable dt = new DataTable(); 
da.Fill(dt); 
 
 
for (var i = 0; i < dt.Rows.Count; i++) 
{ 
for (var j = 0; j < dt.Rows[i].ItemArray.Length; j++) 
{ 
  dt.Rows[i].ItemArray[j] = dt.Rows[i].ItemArray[j].ToString().Trim(); 
} 
}//datasource 
 
return dt; 
}} 
 
Step 2:  
Call the GetSQLResult method in each method of PivotGrid WebAPI controller to feed datasource to the control.(Like, InitializeGrid, fetchMembers..etc.) 
 
Code Snippet:[C#] 
public Dictionary<string, object> InitializeGrid(Dictionary<string, object> jsonResult) 
{ 
htmlHelper.PivotReport = BindDefaultData(); 
dict = htmlHelper.GetJsonData(jsonResult["action"].ToString(), dbquery.GetSQLResult(null));  
return dict; 
} 


 

Please let us know if you need any further assistance. 

Arulraj A 



GU Guadalupe March 21, 2019 02:33 PM UTC

Hello
I cant view the example with VisualStudio.



GU Guadalupe March 21, 2019 08:59 PM UTC

Hello
I need use pivotgrid with to view of SQL Entity Framework.
This is possible?


AA Arulraj A Syncfusion Team March 22, 2019 06:53 AM UTC

Hi Guadalupe, 

Thanks for the update. 

We have provided the sample as per your requirement. The sample project can be opened using Visual Studio 2017, the project file name is “PivotDataTable.csproj”. Please check the sample and let us know if you need further assistance on this. 

Arulraj A 



GU Guadalupe March 22, 2019 12:55 PM UTC

Good morning!

I have VisualStudio 2015. Please you can reply the proyect in my version?

Thank you!


AA Arulraj A Syncfusion Team March 25, 2019 08:45 AM UTC

Hi Guadalupe, 

Thanks for the update. 

As per your requirement we have prepared sample in 4.5 framework which will work in Visual Studio 2015. 

Please let us know if you have any concerns. 
 
Arulraj A 


Loader.
Up arrow icon