GridSwitchColumn inside SfDataGrid checks automatically on scroll.

I'm using SfDataGrid and have a column with GridSwitchColumn. Everytime I scroll the datagrid, the switch at the bottom of the grid checks automatically. How can I fix this?

5 Replies 1 reply marked as answer

SS Sivaraman Sivagurunathan Syncfusion Team August 7, 2020 09:30 AM UTC

Hi Gangatharan 

Thanks for using Syncfusion controls. 

We have checked your reported issue from our side. Unfortunately, the issue does not reproduced from our side. we have prepared the sample based on your code snippet. We have attached the tested sample for your reference you can download the same from the below link. If the issue still occurs from your side please revert us with modified sample. With Xamarin.Forms version and device details. It will help us to provide the better solution. 



Regards,
Sivaraman S 



GB Gangatharan Baskaran August 7, 2020 09:43 AM UTC

Sorry, I did not mean only the check box at bottom. I figured out what was the issue. I'll explain it. I have a GridCellSwitchRenderer class to send some data to server when a user checks in a box. If there is already someone check in, the checkbox will appear ticked on load. If there are some checkboxes  that already checked appear at the bottom part of the grid and it did not show yet in the grid view, when I scroll, the already checked boxes triggers the GridCellSwitchRenderer class and send some duplicate data to server. At the video you sent also you can see the animation of checkbox when you scroll the grid. The checkboxes at the below part checks according to isClosed once it appears on the view. Hope you can understand. How can I fix it?


KK Karthikraja Kalaimani Syncfusion Team August 10, 2020 01:17 PM UTC

Hi Gangatharan, 
The behavior of SfDataGrid scrolling is based on virtualization concept,i.e., if we scroll the rows, then the view used in first row is again re-rendered to its last row and we reset the binding for a cell. So, only toggled event gets triggers for true cases.

Regards,
Karthik Raja
 



GB Gangatharan Baskaran August 14, 2020 01:25 AM UTC

How can I stop it from triggering for already toggled switches. Because it keep sending duplicate data to server. I want it trigger for newly toggled switch only.


KK Karthikraja Kalaimani Syncfusion Team August 14, 2020 01:06 PM UTC

Hi Gangatharan,

Your requirement can be achieved by checking the Database server checkbox value with toggled event checkbox value and if both values same, you can skip calling the DataBase. If both values different, you can call the DataBase. You can pass the DataBase collection to Custom Switch Renderer class through constructor and check these collections with current item in toggled event. For more details please the below code snippet.

Code snippet :

 

this.dataGrid.CellRenderers.Remove("Switch"); 
            this.dataGrid.CellRenderers.Add("Switch", new MySwitchRenderer(DataBaseCollection));
….

public class MySwitchRenderer : GridCellSwitchRenderer 
    { 
        ObservableCollection<OrderInfo> dataBase; 
        public MySwitchRenderer(ObservableCollection<OrderInfo> DataBaseCollection) 
        { 
            dataBase = DataBaseCollection; 
        } 
        public override void OnInitializeDisplayView(DataColumnBase dataColumn, SfSwitchControl view) 
        { 
            base.OnInitializeDisplayView(dataColumn, view); 
            view.Toggled += View_Toggled; 
        } 
 
        private void View_Toggled(object sender, Xamarin.Forms.ToggledEventArgs e) 
        { 
            var item = ((sender as SfSwitchControl).BindingContext as OrderInfo); 
 
            if (!dataBase.Contains(item)) 
            { 
              // DataBase opearion here 
              // Also change this.dataBase item value to avoid duplicate calling 
            } 
        } 
    } 


We hope this will meets your requirement.

Regards,
Karthik Raja
 


Marked as answer
Loader.
Up arrow icon