Select single cell per row

1 Answer 133 Views
Grid
Faz
Top achievements
Rank 1
Iron
Faz asked on 19 Apr 2022, 03:15 AM

Hi 

I like to highlight one cell per row then get the highlighted cell and set a value to another cell on the same row.

for Question 1 ,A is selected so if that's the correct answer then "Raw score" column has to be set to 1

user can only one of A,B,C,D or No answer per row.

is this possible?

Thanks

Faz

1 Answer, 1 is accepted

Sort by
0
Accepted
Nikolay
Telerik team
answered on 21 Apr 2022, 09:31 AM

Hi Faz,

Is the Grid configured for incell editing? If this is so you can use the cellClose event handler to update the Raw Score model property depending on another model property using the set() method. For example:

            cellClose: function(e) {
              if(e.model.Discontinued === true) {
                e.model.set("UnitsInStock", 1)
              } else {
                e.model.set("UnitsInStock", 0)
              }
            }

Here is a Dojo demo demonstrating this: https://dojo.telerik.com/INaMODEh

Let me know if you have any questions.

Regards,
Nikolay
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/.

Faz
Top achievements
Rank 1
Iron
commented on 27 Apr 2022, 04:47 AM

Thanks for the reply Nikolay.

Decided to implement checkbox to achieve this, however I'm not sure how to get currently editing row on checkbox click event.

I have to find  eg: when B is clicked  then find if C also is checked or not. for each row I need to do this and update a column on the same row depending on the combination.

this is my ClientTemplate for checkbox

 columns.Bound(c => c.AnswerB).Title("B").Width(80).ClientTemplate("<input id='AnswerB' name='chk' class='checkbox' type='checkbox' value='#=AnswerB#' # if (AnswerB) { # checked='checked' # } # onclick='onAnswerClick(this)'/>");

and click handler


    function onAnswerClick(me) {
         var grid = $("#AnswersGrid").data("kendoGrid");
        var row = $(this).closest("tr");
        var dataItem = grid.dataItem(row);
        console.log(row)
        console.log(dataItem) <---- Is Null

   }

dataItem is returning null so  I cannot check other columns on the row.

Can you please let me know how this can be achieved?

 

Thanks

Faz

 

Nikolay
Telerik team
commented on 29 Apr 2022, 02:19 PM

Hi Faz,

I recommend utilizing the approach demonstrated in the following article:

https://docs.telerik.com/kendo-ui/knowledge-base/grid-with-checkbox-column

Here is a Dojo for two checkbox columns: https://dojo.telerik.com/EbEmIgAR

Let me know if you need further assiatcne.

Regards,

nikolay

Tags
Grid
Asked by
Faz
Top achievements
Rank 1
Iron
Answers by
Nikolay
Telerik team
Share this question
or