event of a sfdatagrid within a sfpopup

Good morning, I am implementing a project in which I am not using MVVM and I have a problem when getting the action of a button that is in an sfdatagrid which in turn is in an sfpopup.

The method is the following:

Clicking on a button opens a sfpopup that contains an sfdatagrid, the idea is that selecting a button from one of the sfdatagrid rows will take me to another page.

The sfpopup datatemplate is loaded into a separate class.

11 Replies 1 reply marked as answer

SS Sivaraman Sivagurunathan Syncfusion Team August 10, 2020 01:23 PM UTC

Hi David, 

Thanks for using Syncfusion controls. 

We have checked your query. you can achieve you requirement by using the GridTemplateColumn. You can load the Button in GridTemplateColumn and navigate to the next page using button clicked event. Or you can use GridTapped event to navigate to next page. we have prepared the sample based on your requirement and attached for your reference you can download the same from the below link. 


Regards, 
Sivaraman S 



DA David August 11, 2020 03:49 PM UTC

Thanks for the prompt reply, but the example is in the case the datatemplate is in the same class, but what if the datatemplate is created in a separate class?




the button is created in the other class, how can I get the action in the main class?


SS Sivaraman Sivagurunathan Syncfusion Team August 12, 2020 10:18 AM UTC

Hi David, 

Thanks for the update. 

We could not able to understand your query. Can you please share your code snippet for your better understanding. Please share the following details. 

1.How you created the popup, DataGrid, and DataTemplate? 
2.Where you try to access the button? 
3. If possible share the sample. It will help us to provide the better solution. 

Regards, 
Sivaraman S  



DA David August 12, 2020 02:05 PM UTC


Here I send you the sample, as I mentioned, the datagrid is in one class and the data template in another.

How can I get the button event from the datagrid?


I am sending you the link where the sample is.

https://drive.google.com/file/d/1a7bRZK8Awb41v2M26_txMRFQvr2Rny8i/view?usp=sharing


SS Sivaraman Sivagurunathan Syncfusion Team August 13, 2020 06:29 AM UTC

Hi David, 

Thanks for you update. 

We have checked your attached sample. If you create the ImageButton instance inside the DataTemplate we cannot access the in the MainPage. So you have to create the ImageButton instance outside the DataTemplate and create it as internal ImageButton. Den you can access the ImageButton in MainPage. We have modefide the sample and attached for your reference. You can download the same from the below link. 


Regards, 
Sivaraman S 



DA David August 13, 2020 12:53 PM UTC


Thank you very much for the answer, it seems to me that I had already tried that option, and the problem I have is that when I do it that way, the button does not appear, therefore I cannot click it.

I already put the image to the android project





This happens if I create the button inside the datatemplate, The button appears but I cannot access its events.




SS Sivaraman Sivagurunathan Syncfusion Team August 14, 2020 11:30 AM UTC

Hi David, 

Thanks for the update. 

You can overcome the issue by using GridTapped event. For the you just load the image inside the Template column and set the image InputTransparent as True so that the touch pass to SfDataGrid. And check the condition for that template column. Please refer the following code snippet. 


 
GridTemplateColumn columna5 = new GridTemplateColumn 
{ 
    MappingName = "Plazoap", 
    HeaderText = "Boton", 
    ColumnSizer = ColumnSizer.Auto, 
    HeaderFontAttribute = FontAttributes.Bold 
}; 
 
var datatemplate = new DataTemplate(() => 
{ 
    var boton = new ImageButton(); 
    boton.InputTransparent = true; 
    boton.Source = "Edit_icon.png"; 
    boton.BackgroundColor = Color.Red; 
    boton.Padding = new Thickness(10, 10, 10, 10); 
    return boton; 
}); 
 
columna5.CellTemplate = datatemplate; 

private async void SfTablaExpedientes_GridTapped(object sender, GridTappedEventArgs e) 
{ 
    if (e.RowColumnIndex.ColumnIndex == 4) 
    { 
        await Navigation.PushAsync(new NewPage()); 
    } 
} 



We have modified the same and attached for your reference you can download the same from the below link. 


Regards, 
Sivaraman S 



DA David August 14, 2020 05:29 PM UTC

Thank you very much for the answer, I implemented it, but I have a little problem. That when pressing on the fourth row, where the button is, the GridTapped does not work since the button is touched, therefore nothing happens.


SS Sivaraman Sivagurunathan Syncfusion Team August 17, 2020 06:17 AM UTC

Hi David, 

Thanks for the update. 

We have checked your query and try to reproduce the reported issue from our side. Unfortunately we are unable to reproduce the reported issue from our side. It is working fine as expected. In which platform, you have face the issue. we have attached the rested 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 and device details. It will help us to provide the better solution.    


Regards, 
Sivaraman S 


Marked as answer

DA David August 17, 2020 02:58 PM UTC

Thank you so much! This example answers my question.


SS Sivaraman Sivagurunathan Syncfusion Team August 18, 2020 05:31 AM UTC

Hi David, 

We are happy to hear from you. Please get in touch with us if you would require any further assistance.    
   
Regards,    
Sivaraman S    


Loader.
Up arrow icon