ej.responsive.css
ejgrid.responsive.css |
@Html.EJS().Grid("LocalData").Columns(col =>
{
col.Type("checkbox").Width("80").Add();
col.Field("Order ID").HeaderText("Order ID").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Width("120").Add();
. . .
}).AllowPaging().AllowFiltering().Render()
@Html.EJS().Uploader("UploadFiles").AutoUpload(false).AsyncSettings(new Syncfusion.EJ2.Inputs.UploaderAsyncSettings { SaveUrl = "/Home/Save" }).Success("success").Render()
<script>
function success(args) {
var grid = document.getElementsByClassName('e-grid')[0].ej2_instances[0];
var griddata = JSON.parse(args.e.target.responseText);
grid.dataSource = griddata;
}
</script> |
using Syncfusion.XlsIO;
using System.Data;
. . .
public string Save()
{
string directoryPath = "D:/App_Data/TempData/";
if (!Directory.Exists(directoryPath))
Directory.CreateDirectory(directoryPath);
try
{
if (System.Web.HttpContext.Current.Request.Files.AllKeys.Length > 0)
{
for (int i = 0; i < System.Web.HttpContext.Current.Request.Files.AllKeys.Length; ++i)
{
var httpPostedFile = System.Web.HttpContext.Current.Request.Files[i];
if (httpPostedFile != null)
{
filePath = Path.Combine(directoryPath, httpPostedFile.FileName);
if (!System.IO.File.Exists(filePath))
{
using (var fileStream = new FileStream(filePath, FileMode.Create))
{
ExcelEngine excelEngine = new ExcelEngine();
//Loads or open an existing workbook through Open method of IWorkbooks
fileStream.Position = 0;
IWorkbook workbook = excelEngine.Excel.Workbooks.Open(httpPostedFile.InputStream);
IWorksheet worksheet = workbook.Worksheets[0];
// Read data from the worksheet and Export to the DataTable.
DataTable table = worksheet.ExportDataTable(worksheet.UsedRange, ExcelExportDataTableOptions.ColumnNames);
ViewBag.data = JsonConvert.SerializeObject(table, Formatting.Indented, new JsonSerializerSettings { Converters = new[] { new Newtonsoft.Json.Converters.DataTableConverter() } });
}
return (ViewBag.data);
}
else
{
return ("File already exists");
} }
}
}
return ("No file in request"); ;
}
catch (Exception e)
{
return e.Message;
}
} |
|
@Html.EJS().Button("State").Content("Grid_State").Render()
@Html.EJS().Grid("Grid").DataSource((IEnumerable<Object>)ViewBag.datasource).Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").Add();
. . .
}).AllowSorting().AllowPaging().AllowFiltering().Render()
<script>
document.getElementById('State').onclick = (e) => {
var grid = document.getElementsByClassName('e-grid')[0].ej2_instances[0];
var dataManager = new ej.data.DataManager({adaptor: new ej.data.UrlAdaptor });
// generating grid query
var query = grid.renderModule.data.generateQuery()
// process the query which can be bound to “DataManagerRequest” class in server
var result = dataManager.adaptor.processQuery(dataManager, query);
var ajax = new ej.base.Ajax({
url: "/Home/gridState",
type: "POST",
contentType: "application/json",
data: result.data,
});
ajax.send().then(function (data) {
console.log(JSON.parse(data));
}).catch(function (xhr) {
console.log("Fail")
});
}</script> |
public ActionResult gridState(DataManagerRequest dm)
{
return Json(dm);
} |
|
Sir I am using sf uploader , it does not get physical path of file
my code is below.
<SfDialog Width="500" @bind-Visible="@IsVisible" IsModal="true">
<DialogTemplates>
<Content>
<SfUploader AutoUpload="false" AllowMultiple=false AllowedExtensions=".xls, .xlsx">
<UploaderEvents ValueChange="OnChange"></UploaderEvents>
</SfUploader>
</Content>
</DialogTemplates>
</SfDialog>
@code{
private async void OnChange( UploadChangeEventArgs args )
{
var file = args.Files[0];
var path = file.FileInfo.Name;
}
}