|
554 | 554 |
|
555 | 555 | #get-column-state-from-code |
556 | 556 |
|
557 | | -@* Click the button, reorder some columns, maybe lock one of them, hide another, and click the button again to see how the state changes but the order of the columns in the state collection remains the same. This example also shows a workaround for getting the Field of the column that will be availale in a future release as part of the column state. *@ |
558 | | - |
559 | | -@using Telerik.DataSource; |
| 557 | +@* Click the button, reorder some columns, maybe lock one of them, hide another, and click the button again to see how the state changes but the order of the columns in the state collection remains the same. *@ |
560 | 558 |
|
561 | 559 | <TelerikButton OnClick="@GetColumnsFromState">Get the state of the Columns</TelerikButton> |
562 | 560 |
|
|
580 | 578 | </TelerikTreeList> |
581 | 579 |
|
582 | 580 | @code { |
583 | | - public TelerikTreeList<Employee> TreeListRef { get; set; } = new TelerikTreeList<Employee>(); |
584 | | - |
585 | | - //part of workaround for getting the field too |
586 | | - public List<string> ColumnFields => new List<string> |
587 | | - { |
588 | | - nameof(Employee.Name), |
589 | | - nameof(Employee.Id), |
590 | | - nameof(Employee.EmailAddress), |
591 | | - nameof(Employee.HireDate) |
592 | | - }; |
593 | | - public string Logger { get; set; } = String.Empty; |
594 | | - |
595 | | - public async Task GetColumnsFromState() |
| 581 | + private TelerikTreeList<Employee>? TreeListRef { get; set; } |
| 582 | + |
| 583 | + private string Logger { get; set; } = String.Empty; |
| 584 | + |
| 585 | + private List<Employee> Data { get; set; } = new(); |
| 586 | + |
| 587 | + private void GetColumnsFromState() |
596 | 588 | { |
597 | | - // final part of the workaround for getting the field |
598 | | - var columnsState = TreeListRef.GetState().ColumnStates; |
| 589 | + var columnsState = TreeListRef!.GetState().ColumnStates; |
599 | 590 |
|
600 | 591 | int index = 0; |
601 | 592 |
|
602 | 593 | foreach (var item in columnsState) |
603 | 594 | { |
604 | | - string columnField = ColumnFields[index]; |
605 | | - |
606 | 595 | bool isVisible = item.Visible != false; |
607 | 596 |
|
608 | | - string log = $"<p>Column: <strong>{columnField}</strong> | Index in TreeList: {item.Index} | Index in state: {index} | Visible: {isVisible} | Locked: {item.Locked}</p>"; |
| 597 | + string log = $"<p>Column: <strong>{item.Field}</strong> | Index in TreeList: {item.Index} | Index in state: {index} | Visible: {isVisible} | Locked: {item.Locked}</p>"; |
609 | 598 | Logger += log; |
610 | 599 | index++; |
611 | 600 | } |
612 | 601 | } |
613 | 602 |
|
614 | | - public List<Employee> Data { get; set; } |
615 | | - |
616 | | - // sample model |
617 | | - |
618 | | - public class Employee |
| 603 | + protected override void OnInitialized() |
619 | 604 | { |
620 | | - // hierarchical data collections |
621 | | - public List<Employee> DirectReports { get; set; } |
622 | | - |
623 | | - // data fields for display |
624 | | - public int Id { get; set; } |
625 | | - public string Name { get; set; } |
626 | | - public string EmailAddress { get; set; } |
627 | | - public DateTime HireDate { get; set; } |
| 605 | + Data = GetTreeListData(); |
628 | 606 | } |
629 | 607 |
|
630 | | - // data generation |
631 | | - |
632 | | - // used in this example for data generation and retrieval for CUD operations on the current view-model data |
633 | 608 | public int LastId { get; set; } = 1; |
634 | 609 |
|
635 | | - protected override async Task OnInitializedAsync() |
636 | | - { |
637 | | - Data = await GetTreeListData(); |
638 | | - } |
639 | | - |
640 | | - async Task<List<Employee>> GetTreeListData() |
| 610 | + private List<Employee> GetTreeListData() |
641 | 611 | { |
642 | 612 | List<Employee> data = new List<Employee>(); |
643 | 613 |
|
|
684 | 654 | } |
685 | 655 | } |
686 | 656 |
|
687 | | - return await Task.FromResult(data); |
| 657 | + return data; |
| 658 | + } |
| 659 | + |
| 660 | + public class Employee |
| 661 | + { |
| 662 | + public int Id { get; set; } |
| 663 | + public string Name { get; set; } = string.Empty; |
| 664 | + public string EmailAddress { get; set; } = string.Empty; |
| 665 | + public DateTime HireDate { get; set; } |
| 666 | + public List<Employee>? DirectReports { get; set; } |
688 | 667 | } |
689 | 668 | } |
690 | 669 | #end |
|
0 commit comments