different row template according to a value

1 Answer 225 Views
Grid
Nicolas
Top achievements
Rank 1
Iron
Nicolas asked on 29 Nov 2021, 11:47 AM | edited on 30 Nov 2021, 08:00 AM

Hello,

Is it possible to have a different template per row according to a value of a column in the grid?

Example:

If ForecastType=1

If ForecastType=2

 

If ForecastType=3

 

yellow areas are editable

1 Answer, 1 is accepted

Sort by
0
Tsvetomir
Telerik team
answered on 02 Dec 2021, 07:36 AM

Hi, Nicolas,

Indeed, it is possible to have different row templates based on a condition. Please find the REPL example below that displays different rows based on a condition from the data item:

https://netcorerepl.telerik.com/wvbQumaB34zVMb2820

As per the editing, please note that it comes from the data source, or, if you would like to dynamically make a field editable/non-editable, I recommend the following article:

https://docs.telerik.com/aspnet-mvc/html-helpers/data-management/grid/how-to/editing/conditionally-editable-columns

I hope you find this helpful.

 

Kind regards,
Tsvetomir
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Nicolas
Top achievements
Rank 1
Iron
commented on 02 Dec 2021, 11:10 AM | edited

Hi,

Thank you for your reply.

For display, it works.

 

Nicolas
Top achievements
Rank 1
Iron
commented on 02 Dec 2021, 02:25 PM

Hi,.

I have another question for the Edit button how do we do it with "ClientRowTemplate"?

Tsvetomir
Telerik team
commented on 03 Dec 2021, 12:38 PM

If you would like to add the edit button to the row, you could get the rendered HTML from the demo below:

https://demos.telerik.com/aspnet-core/grid/editing-inline

Adding an anchor tag with the k-grid-edit class should be sufficient for adding the button to the row of the grid:

<a role="button" class="k-button k-button-icontext k-grid-edit" href="#"><span class="k-icon k-i-edit"></span>Edit</a>

As per the custom scenario with the order of the TD elements, the row template has no limitation on how exactly the elements have to be structured. You could use a combination of HTML and CSS to achieve the design at hand. Usually, such custom scenarios are created by the developer as the support services focus more on the exposed options and how to utilize them rather than providing end-to-end solutions. 

 

 

 

Nicolas
Top achievements
Rank 1
Iron
commented on 06 Dec 2021, 10:26 AM

Hi,

It works but my fields are more editable.

I found another solution.


columns.Bound(p => p.B_M0_1).Title($"{DateTime.UtcNow.ToString("MMM yy")}  </br> Billable </br> Consulting")
    .ClientTemplate("<p style = 'background-color : #=colorBaseline(ForecastStatus)#'>#=isnullBaseline(B_M0_1) # </p> <p style = 'background-color : #=colorForecast(ForecastStatus)#'>#= isnullForecast(F_M0_1) # </p>").Width(84).Filterable(false).Editable("productNameEditable");


function isnullBaseline(valeur) {
        return valeur === null ? "Baseline" : valeur;       
    }
	
function colorBaseline(status) {
    return status === 28 ? "yellow" : "white";       

}

Thank you for your reply
Tsvetomir
Telerik team
commented on 06 Dec 2021, 01:40 PM

Hi Nicolas, indeed, this is the cleanest and most recommended for dynamically enabling the editing for a specific field. However, this requires for setting up both - the column in the Columns declaration as well as in the ClientRowTemplate.
Tags
Grid
Asked by
Nicolas
Top achievements
Rank 1
Iron
Answers by
Tsvetomir
Telerik team
Share this question
or