@@ -856,31 +856,30 @@ This event fires when each Grid row renders. This can happen in the following ca
856856> caption Use the OnRowRender event to apply custom styles to Grid rows based on certain condition
857857
858858```` RAZOR
859- @* Conditional styling/formatting for rows (including locked/frozen columns). *@
860-
861859<style>
862- /*the following selectors target the locked/frozen columns*/
863- /*===*/
864- .k-grid .k-master-row.myCustomRowFormatting .k-grid-content-sticky,
865- .k-grid .k-master-row.myCustomRowFormatting.k-alt .k-grid-content-sticky
866- /*===*/ {
867- background-color: inherit;
860+ /* Conditional row background */
861+ .k-grid .k-master-row.myCustomRowFormatting {
862+ background-color: #fda;
868863 }
869-
870- .k-grid .k-master -row.myCustomRowFormatting:hover {
871- background-color: red !important ;
864+ /* Conditional row hover background */
865+ .k-grid .k-table-tbody>.k-table -row.myCustomRowFormatting:hover {
866+ background-color: #fb8 ;
872867 }
873868
874- .k-grid .k-master-row.myCustomRowFormatting {
875- background-color: #90EE90;
869+ /* Conditional row background for frozen columns */
870+ .k-grid .k-master-row.myCustomRowFormatting .k-table-td.k-grid-content-sticky,
871+ .k-grid .k-master-row.myCustomRowFormatting.k-table-alt-row .k-table-td.k-grid-content-sticky {
872+ background-color: inherit;
876873 }
877874</style>
878875
879- <TelerikGrid Data="@MyData"
880- Height="446px"
876+ <TelerikGrid Data="@GridData"
877+ Height="360px"
878+ OnRowRender="@OnRowRenderHandler"
881879 Pageable="true"
882- Width="450px"
883- OnRowRender="@OnRowRenderHandler">
880+ SelectionMode="@GridSelectionMode.Multiple"
881+ @bind-SelectedItems="@GridSelectedItems"
882+ Width="450px">
884883 <GridColumns>
885884 <GridColumn Field="@(nameof(SampleData.Id))" Width="120px" Locked="true" />
886885 <GridColumn Field="@(nameof(SampleData.Name))" Width="200px" Title="Employee Name" />
@@ -889,33 +888,31 @@ This event fires when each Grid row renders. This can happen in the following ca
889888</TelerikGrid>
890889
891890@code {
892- void OnRowRenderHandler(GridRowRenderEventArgs args)
891+ private IEnumerable<SampleData> GridSelectedItems { get; set; } = new List<SampleData>();
892+
893+ private void OnRowRenderHandler(GridRowRenderEventArgs args)
893894 {
894895 var item = args.Item as SampleData;
895896
896- //conditional applying Class
897- if (item.Name.Contains("5") || item.Name.Contains("6"))
898- {
899- args.Class = "myCustomRowFormatting";
900- }
901- if (item.Id < 2)
897+ // Conditional row Class
898+ if (item.Id % 3 == 0)
902899 {
903900 args.Class = "myCustomRowFormatting";
904901 }
905902 }
906903
907- public IEnumerable<SampleData> MyData = Enumerable.Range(1, 30).Select(x => new SampleData
904+ private IEnumerable<SampleData> GridData = Enumerable.Range(1, 30).Select(x => new SampleData
908905 {
909906 Id = x,
910- Name = "name " + x ,
911- Team = "team " + x % 5
907+ Name = $"Name {x}" ,
908+ Team = $"Team { x % 5 + 1}"
912909 });
913910
914911 public class SampleData
915912 {
916913 public int Id { get; set; }
917- public string Name { get; set; }
918- public string Team { get; set; }
914+ public string Name { get; set; } = string.Empty;
915+ public string Team { get; set; } = string.Empty;
919916 }
920917}
921918````
0 commit comments