ahmedaziz
Well-known member
- Joined
- Feb 22, 2023
- Messages
- 55
- Programming Experience
- 1-3
I work on asp.net core blazer server side . I face issue I can't export radzen data grid to excel after filter data on it .
so when page load list of Data source of radzen data grid it display 10 records
after that I make filter to any column on radzen data grid then it display 4 records so
when press button export to excel it export 10 rows meaning it export radzen data grid
before filter .
but correct it must export 4 rows to excel .
so How to export radzen data grid to excel after filter ridzen data grid ?
so when page load list of Data source of radzen data grid it display 10 records
after that I make filter to any column on radzen data grid then it display 4 records so
when press button export to excel it export 10 rows meaning it export radzen data grid
before filter .
but correct it must export 4 rows to excel .
so How to export radzen data grid to excel after filter ridzen data grid ?
I need to display 4 records when export to excel after filter:
private async Task ExportToExcel()
{
ExceldatabaseData = databaseData.Select(p => new CopyExcelDatabaseClass
{
DBID = p.dbid,
DBName = p.databaseName,
ServerID = p.serverID,
ServerName = p.serverName,
Severity = p.serverity,
BackupProcedure = p.backUpProcedure,
Remarks = p.remarks,
OwnerFileNo = p.ownerfilenumber,
OwnerFileName = p.ownerfilename,
IsActive = p.isActive
}).ToList();
ExcelPackage.LicenseContext = LicenseContext.Commercial;
var stream = new MemoryStream();
using (var package = new ExcelPackage(stream))
{
var worksheet = package.Workbook.Worksheets.Add("DatabaseList");
//worksheet.Cells.LoadFromCollection(databaseData, true);
worksheet.Cells.LoadFromCollection(ExceldatabaseData, true);
package.Save();
}
var buffer = stream.ToArray();
var fileName = $"Database_{DateTime.Now:yyyyMMddHHmmss}.xlsx";
await JS.InvokeAsync<object>("saveAsFile", fileName, Convert.ToBase64String(buffer));
}
java script function
window.saveAsFile = (filename, bytesBase64) => {
const link = document.createElement('a');
link.download = filename;
link.href = 'data:application/octet-stream;base64,' + bytesBase64;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
};
public class CopyExcelDatabaseClass
{
[DisplayName("DB ID")]
public int DBID { get; set; }
[DisplayName("DB Name")]
public string DBName { get; set; }
[DisplayName("Server ID")]
public int ServerID { get; set; }
[DisplayName("Server Name")]
public string ServerName { get; set; }
public string Severity { get; set; }
[DisplayName("Backup Procedure")]
public string BackupProcedure { get; set; }
public string Remarks { get; set; }
[DisplayName("Owner File No")]
public string OwnerFileNo { get; set; }
[DisplayName("Owner File Name")]
public string OwnerFileName { get; set; }
[DisplayName("Is Active")]
public bool IsActive { get; set; }
}
private IEnumerable<DatabaseClass> databaseData = Array.Empty<DatabaseClass>();
private async Task RefreshList()
{
var request = new HttpRequestMessage(HttpMethod.Get, config["API_URL"] + "Database/GetAllDatabaseDetails");
var client = ClientFactory.CreateClient();
var response = await client.SendAsync(request);
using var responsestream = await response.Content.ReadAsStreamAsync();
databaseData = await JsonSerializer.DeserializeAsync<List<DatabaseClass>>(responsestream);
}
protected override async Task OnInitializedAsync()
{
await RefreshList();
}