Issue calling a function in BeforeChange

Tags: #<Tag:0x00007f8b1da89e18>

Morning, I have the following table:

var hot = new Handsontable(container, {

            data: @Html.Raw(Json.Encode(Model.Decisions)),                
            cells: function(row, col) {
                var cellProperties = {};

                cellProperties.renderer = "rowColourRenderer"; // uses lookup map
                return cellProperties;                    
            },

            beforeChange: function(changes, src) {
                //if (src !== 'internal-call') {
                //    this.setDataAtCell(changes[0][0], 2, 'Row changed', 'internal-call')
                //}
                var row = changes[0][0];
                alert("row: " + row);


                var reason = changes[0][3];
                alert("new reason: " + reason);

                var decision =  hot.getDataAtCell(row,0);
                alert("decision: " + decision);


                var temp = getReasonFromDecision(decision, reason);
                alert("temp: " + temp);
                //this.setDataAtCell(changes[0][0], 1, temp, 'internal-call')

            },

and I am trying to call a function getReasonFromDecision passing decision and reason. But my page hangs. I’m not sure what I’m doing wrong. My function is:

function getReasonFromDecision(decision, reason) {
var temp = Model.ReasonFromDecision(decision, reason);
return temp;
}

and in the model the code is:

public string ReasonFromDecision(string decision, string reason)
{
string temp = “”;
if (string.IsNullOrEmpty(reason))
{
List decisions = db.DecisionCodes.ToList();

            var result = (from d in decisions
                          where d.Code == decision
                          select d).FirstOrDefault();


            temp = result.Reason == null ? "" : result.Reason;
        }
        else
        {
            temp = reason;
        }
        return temp;
    }

The code is never run in the model - I have a breakpoint there.

Hey @maxine.williams

can you share the code via JSFiddle? It will be much easier to debug.

I don’t know how to do that sorry. Is there a page with instructions on?

I’ve been googling a lot and I’ve managed to run a JsonResult function with Ajax. I wasn’t calling my function correctly by the looks of it.
Thank you for looking into it for me :smile:

so maybe it will be easier for you to share a .zip? If so please send it to me at support@handsontable.com