Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2020330
chore(grid): better CRUD service mimic on editign overview page
marin-bratanov Nov 6, 2020
b715484
chore(grid): inline editing better crud mimic
marin-bratanov Nov 7, 2020
f0d76e5
chore(grid): popup editing better crud mimic
marin-bratanov Nov 7, 2020
093c921
chore(grid): incell editing better crud mimic
marin-bratanov Nov 7, 2020
8021b68
chore(grid): autogetn columns editing better crud mimic
marin-bratanov Nov 7, 2020
e4aa22f
chore(grid): insertion to generate ID
marin-bratanov Nov 7, 2020
b8975cb
chore(grid): command column editing better crud mimic
marin-bratanov Nov 7, 2020
a47dc45
chore(grid): state dics editing better crud mimic
marin-bratanov Nov 7, 2020
23e056f
chore(grid): editor template better crud mimic
marin-bratanov Nov 7, 2020
340242d
chore(grid): toolbar better CRUD mimic
marin-bratanov Nov 7, 2020
2033d2b
chore(listview): better CRUD mimic
marin-bratanov Nov 7, 2020
3827aef
chore(scheduler): better CRUD service mimic
marin-bratanov Nov 7, 2020
3e323a8
docs(grid): clarify why async Task and not async void
marin-bratanov Nov 7, 2020
1130076
chore(treelist): autogen columns better CRUD mimic
marin-bratanov Nov 7, 2020
49fb075
chore(treeList): command column better CRUD mimic
marin-bratanov Nov 7, 2020
4ff3d3e
chore(treeList): incell edit better CRUD mimic
marin-bratanov Nov 7, 2020
27590f7
chore(treeList): inline edit better CRUD mimic
marin-bratanov Nov 7, 2020
93b9c04
chore(treeList): popup editing better CRUD mimic
marin-bratanov Nov 7, 2020
01dbe5c
chore(treeList): editing overview better CRUD mimic
marin-bratanov Nov 7, 2020
fffabf2
docs(treelist): improvements on editing notes
marin-bratanov Nov 7, 2020
04afa4c
chore(treeList): state sampel better CRUD mimic
marin-bratanov Nov 7, 2020
335473f
chore(treeList): editor template better CRUD mimic
marin-bratanov Nov 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 76 additions & 94 deletions components/grid/columns/auto-generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,33 +199,30 @@ This example shows how to:
@using System.Collections.ObjectModel

<div style="max-width: 800px;">
<EditForm Model="@DataModel">
<DataAnnotationsValidator />
<ValidationSummary />
<TelerikGrid Data="@GridData"
AutoGenerateColumns="true"
EditMode="GridEditMode.Popup"
Pageable="true"
SelectionMode="GridSelectionMode.Multiple"
@bind-SelectedItems="@SelectedUsers"
PageSize="@PageSize"
OnCreate="@CreateItem"
OnUpdate="@UpdateItem"
OnDelete="@DeleteItem">
<GridToolBar>
<GridCommandButton Command="Add" Icon="add">Add</GridCommandButton>
</GridToolBar>
<GridColumns>
<GridCheckboxColumn />
<GridAutoGeneratedColumns ColumnWidth="200px" />
<GridColumn Field="@nameof(GridDataModel.RegistrationDate)" Title="Registration Date" Width="200px" />
<GridCommandColumn Width="250px">
<GridCommandButton Command="Edit" Icon="edit">Edit</GridCommandButton>
<GridCommandButton Command="Delete" Icon="delete">Delete</GridCommandButton>
</GridCommandColumn>
</GridColumns>
</TelerikGrid>
</EditForm>

<TelerikGrid Data="@GridData"
AutoGenerateColumns="true"
EditMode="GridEditMode.Popup"
Pageable="true"
SelectionMode="GridSelectionMode.Multiple"
@bind-SelectedItems="@SelectedUsers"
PageSize="@PageSize"
OnCreate="@CreateItem"
OnUpdate="@UpdateItem"
OnDelete="@DeleteItem">
<GridToolBar>
<GridCommandButton Command="Add" Icon="add">Add</GridCommandButton>
</GridToolBar>
<GridColumns>
<GridCheckboxColumn />
<GridAutoGeneratedColumns ColumnWidth="200px" />
<GridColumn Field="@nameof(GridDataModel.RegistrationDate)" Title="Registration Date" Width="200px" />
<GridCommandColumn Width="250px">
<GridCommandButton Command="Edit" Icon="edit">Edit</GridCommandButton>
<GridCommandButton Command="Delete" Icon="delete">Delete</GridCommandButton>
</GridCommandColumn>
</GridColumns>
</TelerikGrid>


@if (SelectedUsers.Any())
Expand Down Expand Up @@ -253,7 +250,6 @@ This example shows how to:
public List<GridDataModel> GridData { get; set; }
public IEnumerable<GridDataModel> SelectedUsers { get; set; } = new ObservableCollection<GridDataModel>();
public int PageSize { get; set; } = 3;
GridDataModel DataModel = new GridDataModel();

#region data model with annotations
public class GridDataModel
Expand Down Expand Up @@ -290,106 +286,92 @@ This example shows how to:
GridDataModel item = (GridDataModel)args.Item;

// perform actual data source operations here through your service
GridDataModel updatedItem = await ServiceMimicUpdate(item);
await MyService.Update(item);

// update the local view-model data
var index = GridData.FindIndex(i => i.Id == updatedItem.Id);
if (index != -1)
{
GridData[index] = updatedItem;
}
// update the local view-model data with the service data
await GetGridData();
}

async Task DeleteItem(GridCommandEventArgs args)
{
GridDataModel item = (GridDataModel)args.Item;

// perform actual data source operation here through your service
bool isDeleted = await ServiceMimicDelete(item);
await MyService.Delete(item);

if (isDeleted)
{
// update the local view-model data
GridData.Remove(item);
}
// update the local view-model data with the service data
await GetGridData();
}

async Task CreateItem(GridCommandEventArgs args)
{
GridDataModel item = (GridDataModel)args.Item;

// perform actual data source operation here through your service
GridDataModel insertedItem = await ServiceMimicInsert(item);
await MyService.Create(item);

// update the local view-model data
GridData.Insert(0, insertedItem);
// update the local view-model data with the service data
await GetGridData();
}

#endregion

// the following three methods mimic an actual data service that handles the actual data source
// you can see about implement error and exception handling, determining suitable return types as per your needs
// an example is available here: https://github.com/telerik/blazor-ui/tree/master/grid/remote-validation

async Task<GridDataModel> ServiceMimicInsert(GridDataModel itemToInsert)
async Task GetGridData()
{
// in this example, we just populate the fields, you project may use
// something else or generate the updated item differently
GridDataModel updatedItem = new GridDataModel()
{
// the service assigns an ID, in this sample we use only the view-model data for simplicity,
// you should use the actual data and set the properties as necessary (e.g., generate nested fields data and so on)
Id = GridData.Count + 1,
Username = itemToInsert.Username,
EmailAddress = itemToInsert.EmailAddress,
RegistrationDate = itemToInsert.RegistrationDate,
LocalTime = itemToInsert.LocalTime,
BoughtBooks = itemToInsert.BoughtBooks
};
return await Task.FromResult(updatedItem);
GridData = await MyService.Read();
}

async Task<GridDataModel> ServiceMimicUpdate(GridDataModel itemToUpdate)
protected override async Task OnInitializedAsync()
{
// in this example, we just populate the fields, you project may use
// something else or generate the updated item differently
GridDataModel updatedItem = new GridDataModel()
{
Id = itemToUpdate.Id,
Username = itemToUpdate.Username,
EmailAddress = itemToUpdate.EmailAddress,
RegistrationDate = itemToUpdate.RegistrationDate,
LocalTime = itemToUpdate.LocalTime,
BoughtBooks = itemToUpdate.BoughtBooks
};
return await Task.FromResult(updatedItem);
await GetGridData();
}

async Task<bool> ServiceMimicDelete(GridDataModel itemToDelete)
// the following static class mimics an actual data service that handles the actual data source
// replace it with your actual service through the DI, this only mimics how the API can look like and works for this standalone page
public static class MyService
{
return await Task.FromResult(true);//always successful
}
private static List<GridDataModel> _data { get; set; } = new List<GridDataModel>();

#endregion
public static async Task Create(GridDataModel itemToInsert)
{
itemToInsert.Id = _data.Count + 1;
_data.Insert(0, itemToInsert);
}

#region data generation
protected override void OnInitialized()
{
GridData = new List<GridDataModel>();
for (int i = 0; i < 45; i++)
public static async Task<List<GridDataModel>> Read()
{
if (_data.Count < 1)
{
for (int i = 0; i < 45; i++)
{
_data.Add(new GridDataModel()
{
Id = i,
Username = $"Username {i}",
EmailAddress = $"user{i}@mail.com",
RegistrationDate = DateTime.Now.AddDays(-2),
LocalTime = DateTime.Now
});
}
}

return await Task.FromResult(_data);
}

public static async Task Update(GridDataModel itemToUpdate)
{
GridData.Add(new GridDataModel()
var index = _data.FindIndex(i => i.Id == itemToUpdate.Id);
if (index != -1)
{
Id = i,
Username = $"Username {i}",
EmailAddress = $"user{i}@mail.com",
RegistrationDate = DateTime.Now.AddDays(-2),
LocalTime = DateTime.Now
});
_data[index] = itemToUpdate;
}
}

base.OnInitialized();
public static async Task Delete(GridDataModel itemToDelete)
{
_data.Remove(itemToDelete);
}
}
#endregion
}
````
>caption The result from the code snippet above
Expand Down
72 changes: 46 additions & 26 deletions components/grid/columns/command.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,7 @@ The following code example demonstrates declarations and handling.
public DateTime HireDate { get; set; }
}

List<SampleData> GridData = Enumerable.Range(1, 50).Select(x => new SampleData
{
ID = x,
Name = "name " + x,
HireDate = DateTime.Now.AddDays(-x)
}).ToList();
List<SampleData> GridData { get; set; }

// sample custom commands handling

Expand All @@ -129,36 +124,61 @@ The following code example demonstrates declarations and handling.

}

// sample CUD operations
// sample CRUD operations

private async Task MyUpdateHandler(GridCommandEventArgs args)
{
SampleData theUpdatedItem = args.Item as SampleData;
SampleData updatedItem = await ServiceMimicUpdate(theUpdatedItem);

// update the local view-model data
var index = GridData.FindIndex(i => i.ID == updatedItem.ID);
if (index != -1)
{
GridData[index] = updatedItem;
}
// perform actual data source operations here through your service
await MyService.Update(theUpdatedItem);

// update the local view-model data with the service data
await GetGridData();
}

async Task GetGridData()
{
GridData = await MyService.Read();
}

// the following method mimics an actual data service that handles the actual data source
// you can see about implement error and exception handling, determining suitable return types as per your needs
// an example is available here: https://github.com/telerik/blazor-ui/tree/master/grid/remote-validation
protected override async Task OnInitializedAsync()
{
await GetGridData();
}

async Task<SampleData> ServiceMimicUpdate(SampleData itemToUpdate)
// the following static class mimics an actual data service that handles the actual data source
// replace it with your actual service through the DI, this only mimics how the API can look like and works for this standalone page
public static class MyService
{
// in this example, we just populate the fields, you project may use
// something else or generate the updated item differently
SampleData updatedItem = new SampleData()
private static List<SampleData> _data { get; set; } = new List<SampleData>();

public static async Task<List<SampleData>> Read()
{
ID = itemToUpdate.ID,
HireDate = itemToUpdate.HireDate,
Name = itemToUpdate.Name
};
return await Task.FromResult(updatedItem);
if (_data.Count < 1)
{
for (int i = 1; i < 50; i++)
{
_data.Add(new SampleData()
{
ID = i,
Name = "name " + i,
HireDate = DateTime.Now.AddDays(-i)
});
}
}

return await Task.FromResult(_data);
}

public static async Task Update(SampleData itemToUpdate)
{
var index = _data.FindIndex(i => i.ID == itemToUpdate.ID);
if (index != -1)
{
_data[index] = itemToUpdate;
}
}
}
}
````
Expand Down
Loading