Open akoustov opened 3 years ago
fixed a small problems in my code, found a way to add a record to the grid with
records.Add(record);
recordsGrid.UpdateRow(record);
recordsGrid.Reload();
but sorting in the headers does not work now
after fixing my small problems I can add/delete a record in the grid. right now i have a double entry problem. it starts where in two columns I have only one entry, the second makes a req.validator error. After making the second entry this code(SaveRow() ) runs again and creates the same 2 rows in the grid. If a record is created without a reg.validator error I have only one entry.
void SaveRow(Record2 record) { records.Insert(0, record); //adds the item at front recordsGrid.UpdateRow(record); recordsGrid.Reload(); }
very bad that I have to make this code to avoid double entry when a req.validator fires, do you have better way?
void SaveRow(Record2 record)
{
records.Insert(0, record); //adds the item at front
recordsGrid.UpdateRow(record);
recordsGrid.Reload();
if (record.CheckItems()) //if even one item in the object is null return false
{
records.RemoveAt(0); //adds the item at front
recordsGrid.UpdateRow(record);
recordsGrid.Reload();
}
}
I solved the problem. comments in your code should be entered even simple like this.
//called when the record is submitted and if not all data is entered calls validators after UpdateRow( )
void SaveRow(Record2 record)
{
recordsGrid.UpdateRow(record);
}
//called when the record is submitted and all data is entered void OnCreateRow(Record2 record) { records.Insert(0, record); //adds the item at front recordsGrid.UpdateRow(record); recordsGrid.Reload();
// For production
//dbContext.SaveChanges();
}
Hi guys, I have a blazor app .net core 3.1 where I took as a base the demo- DataGrid InLine Editing (https://blazor.radzen.com/datagrid-inline-edit) to create a grid. From my DB I can load data to the grid, but could not add a new record. My grid has only 2 items: pulldown menu and text box. When I add a record, the record is not going to the list, also edit-save does not work, I have nuget Radzen.Blazor(3.1.5). Here is the code.
@page "/bhr"
@using System @using BhrTools.Data @using Microsoft.EntityFrameworkCore @inject BHRecordService ser
@code { RadzenGrid recordsGrid;
IList records;
IEnumerable totals;
IEnumerable pmmts;
IEnumerable urgs;
IEnumerable campaigns;
IEnumerable clients;
IEnumerable desks;
string DayValue;
string value;
bool gbGate;
DateTime? valueDT = DateTime.Now;
// Record2 record2 = new Record2("3", "123"); recordsGrid.UpdateRow(record); }
// Record2.Customer = dbContext.Customers.Find(Record2.CustomerID); // Record2.Employee = dbContext.Employees.Find(Record2.EmployeeID);
// var recordEntry = dbContext.Entry(record); // if (recordEntry.State == EntityState.Modified) // { // recordEntry.CurrentValues.SetValues(recordEntry.OriginalValues); // recordEntry.State = EntityState.Unchanged; // } }
// dbContext.Remove(record);
// dbContext.Add(Record2);
// Record2.Customer = dbContext.Customers.Find(Record2.CustomerID); // Record2.Employee = dbContext.Employees.Find(Record2.EmployeeID);
}