|
[cshtml]
@Html.EJS().Grid("Grid").DataSource((IEnumerable<Object>)ViewBag.dataSource).Columns(col =>
{
col.Field("OrderID").IsPrimaryKey(true).HeaderText("Order ID").Width("150").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("CustomerID").HeaderText("Customer ID").Width("150").Add();
col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Width("150").Add();
col.Field("UserImage").HeaderText("Image").Edit(new { create = "create", read = "read", destroy = "destroy", write = "write" }).Width("150").Add();
}).AllowPaging(true). EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Dialog); }).Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render()
|
|
function create(args) {
// create target element
elem = document.createElement('input');
return elem;
}
function write(args) {
// EJ2 render Uploader component
uploadObj = new ej.inputs.Uploader({
// get the file through selected event of Uploader
selected: function (args) {
for (var i = 0; i < args.filesData.length; i++) {
getBase64(args.filesData[i].rawFile);
}
},
});
uploadObj.appendTo(elem);
}
function destroy() {
// destroy the component after save
uploadObj.destroy();
}
function read(args) {
// read the custom component(uploader) value
return filt64String; // base64 string return
} |
|
// convert into base64
function getBase64(file) {
var reader = new FileReader();
reader.readAsDataURL(file);
filt64String = reader.result;
}
|
|
<div>
@Html.EJS().Grid("Grid").DataSource(dataManager => { dataManager.Url("/Home/UrlDatasource").UpdateUrl("/Home/Update").InsertUrl("Home/Add").RemoveUrl("Home/Remove").Adaptor("UrlAdaptor"); }).Columns(col =>
{
col.Field("OrderID").IsPrimaryKey(true).HeaderText("Order ID").Width("150").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("CustomerID").HeaderText("Customer ID").Width("150").Add();
col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Width("150").Add();
col.Field("Image").HeaderText("Image").Edit(new { create = "create", read = "read", destroy = "destroy", write = "write" }).Width("150").Add();
}).AllowPaging(true).ActionBegin("actionBegin").EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Dialog); }).Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render()
</div>
. . .
|
|
<style>
.e-dialog.e-edit-dialog{
width: 800px !important;
height: 800px !important;
}
input, select, textarea {
max-width: 790px !important;
}
</style>
|
|
<div>
@Html.EJS().Grid("Grid").DataSource(dataManager => { dataManager.Url("/Home/UrlDatasource").UpdateUrl("/Home/Update").InsertUrl("Home/Add").RemoveUrl("Home/Remove").Adaptor("UrlAdaptor"); }).Columns(col =>
{
col.Field("OrderID").IsPrimaryKey(true).HeaderText("Order ID").Width("150").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
. . .
col.Field("Image").HeaderText("Image").Edit(new { create = "create", read = "read", destroy = "destroy", write = "write" }).Width("150").Add();
}).AllowPaging(true).QueryCellInfo("queryCellInfo").EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Dialog); }).Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render()
|
|
function queryCellInfo(args) {
if (args.column.field === "Image") {
args.cell.setAttribute('aria-label', 'image')
args.cell.innerText = '';
var img = new Image();
img.src = args.data.Image;
args.cell.appendChild(img);
}
}
|
|
[AcceptVerbs("Post")]
public void Save()
{
var fileStream = HttpContext.Current.Request.Files["UploadFiles"];
var fileName = fileStream.FileName;
StorageCredentials storageCredentials = new StorageCredentials(_storageConfig.AccountName, _storageConfig.AccountKey);
CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference(_storageConfig.ImageContainer);
CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName);
await blockBlob.UploadFromStreamAsync(fileStream);
} |
|
@Html.EJS().Grid("Grid").DataSource((IEnumerable<Object>)ViewBag.dataSource).Columns(col => { col.Field("OrderID").IsPrimaryKey(true).HeaderText("Order ID").Width("150").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); col.Field("CustomerID").HeaderText("Customer ID").Width("150").Add(); col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Width("150").Add(); col.Field("UserImage").HeaderText("Image").Edit(new { create = "create", read = "read", destroy ="destroy", write = "write" }).Width("150").Add(); }).AllowPaging(true).EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Dialog); }).Toolbar(new List<string>
() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render() |
|
<script>
function create(args) { // create target element
elem = document.createElement('input'); return elem;
}
function write(args) { // EJ2 render Uploader component
uploadObj = new ej.inputs.Uploader({ // get the file through selected event of Uploader
selected: function (args) {
for (var i = 0; i < args.filesData.length; i++) {
getBase64(args.filesData[i].rawFile);
}
},
}); uploadObj.appendTo(elem);
}
function destroy() { // destroy the component after save
uploadObj.destroy();
}
function read(args) { // read the custom component(uploader) value
return filt64String; // base64 string return
}
</script> |