CellSelected and RowSelected not working with SfGrid (Custom adapter)

Hello,


But now grid initialized like this:

<SfGrid TValue="Article" ID="Grid" AllowSorting="true" AllowFiltering="true" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" Height="315">
    <GridEvents CellSelected="CellSelectedHandler" RowSelected="RowSelectHandler" TValue="Article"></GridEvents>
    <SfDataManager AdaptorInstance="@typeof(ArticleAdapter)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager>
    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" AllowNextRowEdit="true" Mode="@EditMode.Normal"></GridEditSettings>
</SfGrid>

The below functions never get called:

    public void RowSelectHandler(RowSelectEventArgs<Article> args)
    {
        // Here you can customize your code
        var data = args.Data;
    }

    public void CellSelectedHandler(CellSelectEventArgs<Article> args)
    {
        // Here you can customize your code
        var data = args.Data;
    }



5 Replies

SG Sture Gustafsson April 5, 2020 07:39 PM UTC

Hello,

a small update.

Adding AllowSelection="true" to the SfGrid line will not help.

But if I add RowSelecting = "BoxRowSelectingHandler" (and adding of course the function), then I'm not able to select any rows anymore. (And BoxRowSelectingHandler function is not triggered).

-sture


VN Vignesh Natarajan Syncfusion Team April 6, 2020 02:36 PM UTC

Hi Sture,  
 
Thanks for contacting Syncfusion support.  
 
Query: “CellSelected and RowSelected not working with SfGrid (Custom adapter)”  
 
CellSelected event will be triggered only when SelectionMode is of Cell. So by default in Grid SelectionMode will be Row. So while selecting a record, RowSelected event has to be triggered. But from your query, we suspect that you are facing some exception in RowSelected event which causes the reported issue (preventing the RowSelected event from triggering). So kindly share the exception details in Browser console (Ctrl+F12). It will be very help for us to validate the reported issue at our end.   
 
Regards, 
Vignesh Natarajan. 



SG Sture Gustafsson April 6, 2020 04:04 PM UTC

Hello,

This happens when selecting a row:

blazor.server.js:8 Uncaught (in promise) Error: There was an exception invoking 'Trigger'. For more details turn on detailed exceptions in 'CircuitOptions.DetailedErrors'
    at Object.endInvokeDotNetFromJS (blazor.server.js:8)
    at e.<anonymous> (blazor.server.js:8)
    at blazor.server.js:1
    at Array.forEach (<anonymous>)
    at e.invokeClientMethod (blazor.server.js:1)
    at e.processIncomingData (blazor.server.js:1)
    at e.connection.onreceive (blazor.server.js:1)
    at WebSocket.i.onmessage (blazor.server.js:1)
endInvokeDotNetFromJS @ blazor.server.js:8
(anonymous) @ blazor.server.js:8
(anonymous) @ blazor.server.js:1
e.invokeClientMethod @ blazor.server.js:1
e.processIncomingData @ blazor.server.js:1
connection.onreceive @ blazor.server.js:1
i.onmessage @ blazor.server.js:1


This happens when trying to Delete a row:

articlelist2:1 Uncaught (in promise) {dm: e, data: "5e8b4fe26042fa5b2485514c", keyField: "ID", tableName: undefined, query: e, …}
Promise.then (async)
e.getData @ grids-ec5227.min.js:1
e.blazorCallback @ syncfusion-blazor.min.js:1
e.notify @ syncfusion-blazor.min.js:1
r.notify @ syncfusion-blazor.min.js:1
(anonymous) @ grids-ec5227.min.js:1
e.blazorCallback @ syncfusion-blazor.min.js:1
e.blazorCallback @ syncfusion-blazor.min.js:1
e.blazorCallback @ syncfusion-blazor.min.js:1
e.notify @ syncfusion-blazor.min.js:1
e.trigger @ syncfusion-blazor.min.js:1
t.refresh @ grids-ec5227.min.js:1
e.blazorCallback @ syncfusion-blazor.min.js:1
e.blazorCallback @ syncfusion-blazor.min.js:1
e.blazorCallback @ syncfusion-blazor.min.js:1
e.notify @ syncfusion-blazor.min.js:1
r.notify @ syncfusion-blazor.min.js:1
e.deleteRecord @ grids-ec5227.min.js:1
t.deleteRecord @ grids-ec5227.min.js:1
e.deleteRecord @ grids-ec5227.min.js:1
r.deleteRecord @ grids-ec5227.min.js:1
(anonymous) @ grids-ec5227.min.js:1
e.notify @ syncfusion-blazor.min.js:1
e.trigger @ syncfusion-blazor.min.js:1
e.toolbarClickHandler @ grids-ec5227.min.js:1
e.blazorCallback @ syncfusion-blazor.min.js:1
e.notify @ syncfusion-blazor.min.js:1
e.trigger @ syncfusion-blazor.min.js:1
t.clickHandler @ navigations-ec5227.min.js:1



SG Sture Gustafsson April 6, 2020 07:12 PM UTC

Hello,

I made a clean project with only the SfGrid and then I started to insert parts from my own project until it stopped working.
I was able to narrow it down to one line:

Does not work:
        [Key]
        public ObjectId ID { get; set; }  //type is MongoDB.Bson.ObjectId


Does work:
        [Key]
        public int ID { get; set; }


So if the Article class, which is used in the row, contains a property of type MongoDB.Bson.ObjectId then SfGrid Edit + Delete + RowSelected do not work.
Changing only the type to int causes everything to work fine. But, I would need ObjectId to work for my project...



VN Vignesh Natarajan Syncfusion Team April 7, 2020 12:18 PM UTC

Hi Sture,  
 
Thanks for the update.  
 
Query: “Changing only the type to int causes everything to work fine. But, I would need ObjectId to work for my project... 
 
We suspect that the reported issue occur while serializing the Bson ObjectId using the Newtonsoft json. So we suggest you to modify the JsonSerialize settings like below to resolve the reported issue.   
 
public class Order 
   { 
       public int? OrderID { getset; } 
       public string CustomerID { getset; } 
       public DateTime? OrderDate { getset; } 
       public double? Freight { getset; } 
       [JsonConverter(typeof(ObjectIdConverter))] 
       public ObjectId id { getset; } 
   } 
   class ObjectIdConverter : JsonConverter 
   { 
  
       public override bool CanConvert(Type objectType) 
       { 
           return objectType == typeof(ObjectId); 
       } 
  
       public override object ReadJson(JsonReader readerType objectTypeobject existingValueJsonSerializer serializer) 
       { 
           if (reader.TokenType != JsonToken.String) 
               throw new Exception($"Unexpected token parsing ObjectId. Expected String, got {reader.TokenType}."); 
  
           var value = (string)reader.Value; 
           return string.IsNullOrEmpty(value) ? ObjectId.Empty : new ObjectId(value); 
       } 
  
       public override void WriteJson(JsonWriter writerobject valueJsonSerializer serializer) 
       { 
           if (value is ObjectId) 
           { 
               var objectId = (ObjectId)value; 
               writer.WriteValue(objectId != ObjectId.Empty ? objectId.ToString() : string.Empty); 
           } 
           else 
           { 
               throw new Exception("Expected ObjectId value."); 
           } 
       } 
   } 
 
 
For your convenience we have prepared a sample using ObjectId property using our latest version. Please find the sample from below  
 
 
If you are still facing the issue, kindly get back to us with issue reproducible sample or kindly try to reproduce the reported issue in provided sample.   
 
Regards, 
Vignesh Natarajan. 
 


Loader.
Up arrow icon