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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to render Pivot component with Data Table(C#)

Platform: ASP.NET MVC |
Control: PivotGrid

This KB illustrates that how to render Pivot component with Data Table.

Solution:

You can render the pivot components in relational server mode by using the DataTable as DataSource. You can also perform the operations supported by the respective pivot controls. Refer to the following code snippets.

Step 1

In the relational Web API controller, add the following class. Using the GetSQLResult method, you can get data from the local database.

public class DbaseQuery
{
public dynamic GetSQLResult()
{
//-local path of database file(mdf) for sql com
  string conSTR = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + AppDomain.CurrentDomain.BaseDirectory + @"App_Data\Database1.mdf;Integrated Security=True";
 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();
}
 }
 
 return dt;
}
}

Step 2

You should pass the above DataTable as parameter, which is returned from GetSQLResult method in every action such as InitializeClient and nodeDropped of the respective pivot component.

public class RelationalController : ApiController
{
DbaseQuery dbquery = new DbaseQuery();
//…
 
//Here we have used PivotGrid control. You can render other supported Pivot components (PivotClient, PivotChart, PivotGauge) too.
 
[System.Web.Http.ActionName("InitializeGrid")]
System.Web.Http.HttpPost]
public Dictionary<string, object> InitializeGrid(Dictionary<string, object> jsonResult)
{
 
//…
 
var dictionary = htmlHelper.GetJsonData(jsonResult["action"].ToString(), dbquery.GetSQLResult(), jsonResult["valueSorting"].ToString());
 
return dictionary;
}
 
//…
 
[System.Web.Http.ActionName("NodeDropped")]
[System.Web.Http.HttpPost]
public Dictionary<string, object> NodeDropped(Dictionary<string, object> jsonResult)
{
//…
htmlHelper.PopulateData(jsonResult["currentReport"].ToString());
var dictionary = htmlHelper.GetJsonData(jsonResult["action"].ToString(), dbquery.GetSQLResult(), null, jsonResult["dropAxis"].ToString(), jsonResult["headerTag"].ToString(), jsonResult.ContainsKey("filterParams") ? jsonResult["filterParams"].ToString() : null, jsonResult["sortedHeaders"].ToString(), jsonResult["valueSorting"].ToString());
return dictionary;
}
//…
 

 

 

2X faster development

The ultimate ASP.NET MVC UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile