|
public async Task<object> GetData(FetchData param)
{
return await _cache.GetOrCreateAsync("dataSource" + param.Hash,
async (cacheEntry) =>
{
cacheEntry.SetSize(1);
cacheEntry.AbsoluteExpiration = DateTimeOffset.UtcNow.AddMinutes(60);
// Here you need to return raw data
// return new DataSource.PivotViewData().GetVirtualData();
return new DataSource.BusinessObjectsDataView().GetDataTable(); // To connect data base
});
} |
Hi Sivamathi.
I have spent some time looking at the examples and documentation you sent me, but I still have some questions.
From the Pivot Tables' documentation, I understood it could connect to a back-end and, from there, retrieve data to populate the table. This is something I have taken for granted, since all the front-end code I saw in Syncfusion's examples hint at such a connection. The example you provided also mocks this behavihor, which confirms my initial assumption.
However, I’m asked by my superiors to clarify a specific detail: is there any way the front-end React component of the Pivot Tables connects directly to a database?
For example, if I wanted to simply feed it the database credentials, would it be able to use those to connect and retrieve data from a database?
Thanks in advance!
|
public remoteData = new DataManager({
url: "/Home/UrlDatasource",
adaptor: new UrlAdaptor(),
crossDomain: true
}).executeQuery(new Query().take(6)).then((e: ReturnOption) => {
var pivotObj = document.querySelector('.e-pivotview');
if (pivotObj)
(pivotObj as any).ej2_instances[0].dataSourceSettings.dataSource = e.result as IDataSet[];
}).catch((e) => true);
|
|
private readonly IHostingEnvironment _env;
public HomeController(IHostingEnvironment env)
{
_env = env;
}
static string cons;
static SqlConnection con;
public static List<Order> Orders { get; set; }
public IActionResult Index()
{
cons = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + _env.ContentRootPath + @"\Data\NORTHWND.MDF;Integrated Security=True";
con = new SqlConnection(cons);
return View();
}
public static DataSet CreateCommand(string queryString, string connectionString)
{
using (SqlConnection connection = new SqlConnection(
connectionString))
{
SqlDataAdapter adapter = new SqlDataAdapter(queryString, connection);
DataSet dt = new DataSet();
try
{
connection.Open();
adapter.Fill(dt);// using sqlDataAdapter we process the query string and fill the data into dataset
}
catch (SqlException se)
{
Console.WriteLine(se.ToString());
}
finally
{
connection.Close();
}
return dt;
}
}
public object UrlDatasource([FromBody]DataManagerRequest dm)
{
string qs = "SELECT OrderID, ShipCountry, ShipCity FROM dbo.Orders ORDER BY OrderID; ";
DataSet data = CreateCommand(qs, cons);
Orders = data.Tables[0].AsEnumerable().Select(r => new Order
{
OrderID = r.Field<int>("OrderID"),
ShipCountry = r.Field<string>("ShipCountry"),
ShipCity = r.Field<string>("ShipCity"),
}).ToList(); // here we convert dataset into list
IEnumerable<Order> DataSource = Orders;
if (con.State != ConnectionState.Open)
con.Open();
SqlCommand comm = new SqlCommand("SELECT COUNT(*) FROM dbo.Orders", con);
Int32 count = (Int32)comm.ExecuteScalar();
con.Close();
return DataSource;
}
}
public class Order
{
public int OrderID { get; set; }
public string CustomerID { get; set; }
public Nullable<int> EmployeeID { get; set; }
public Nullable<System.DateTime> OrderDate { get; set; }
public Nullable<System.DateTime> RequiredDate { get; set; }
public Nullable<System.DateTime> ShippedDate { get; set; }
public Nullable<int> ShipVia { get; set; }
public Nullable<decimal> Freight { get; set; }
public string ShipName { get; set; }
public string ShipAddress { get; set; }
public string ShipCity { get; set; }
public string ShipRegion { get; set; }
public string ShipPostalCode { get; set; }
public string ShipCountry { get; set; }
} |
|
Query |
Response |
|
I understand we will always need a some sort of back-end to retrieve the data that is to be shown in the Pivot Table as the table needs to retrieve the information it is to display. Is this assumption correct? |
Recently we have provided the server-side engine support to connect the server-side databases directly. Here the entire aggregation will be done in server-side and only the view-port information alone will be passed to client side to render the pivot table. And we didn’t mention the feature in UG documentation yet but will include it asap.
Yes your assumption is correct. It needs WebAPI controller to define your data source. In React App you should mention the controller URL to fetch the information from server-side engine. |
|
Furthermore, I need clarification about the React front-end component itself: it can only retrieve information from a remote database by connecting to whatever sever we have that links directly to the database, correct? |
Yes in React front-end, you couldn’t able to connect your database directly but allows to connect the same database from remote server where it needs only remote server URL. |