How to place button inside Grid

Hello,
Is it possible to place button component inside Grid component in the exact same way as in this thread: https://www.syncfusion.com/forums/161733/how-to-place-button-inside-datagrid. Unfortunatey I'm unable to implement solution presented in mentioned thread in blazor. 
Thanks in advance.

4 Replies 1 reply marked as answer

VN Vignesh Natarajan Syncfusion Team February 16, 2021 05:00 AM UTC

Hi Lukasz,  
 
Thanks for contacting Syncfusion support.  
 
Query: “Is it possible to place button component inside Grid component in the exact same way as in this thread 
 
We have analyzed your query and we do not have direct support to render a button component inside the Grid control. But we have achieved your requirement using DataBound event and JSInterop to render the JavaScript button.  On button click, we have called C# method BtnClick to perform action in Server side.  
 
Refer the below code example.  
 
<SfGrid @ref="Grid" AllowPaging="true" DataSource="@Orders"> 
    <GridEvents DataBound="DataBoundHandler" TValue="Order"></GridEvents> 
</SfGrid> 
  
@code{ 
    SfGrid<Order> Grid { getset; } 
    public List<Order> Orders { getset; } 
  
    [JSInvokable("BtnClick")] 
    public async Task BtnClick() 
    { 
  
    }  
    public void DataBoundHandler(object args) 
    { 
        var dotNetReference = DotNetObjectReference.Create(this); 
        Runtime.InvokeVoidAsync("BtnRender", dotNetReference, Grid.ID); 
    } 
[renderbtn.js] 
var dotnetreffunction BtnRender(ref, Gridid) {    dotnetref = ref;    var element = document.getElementById(Gridid);    setTimeout(function () {         if (element.querySelector(".e-gridcontent .e-content .gridcontentbtn") == null) {            // get the Grid content             var gridcontent = element.querySelector(".e-gridcontent .e-content");            // get the Grid content table             var contenttable = gridcontent.querySelector(".e-gridcontent .e-content table");            // create the button             var button = document.createElement("button");            button.addEventListener("click", Click);            button.innerText = "BUTTON";            // bind the content table width to the button             button.style.width = contenttable.getBoundingClientRect().width.toString() + "px";            button.classList.add("gridcontentbtn");            gridcontent.appendChild(button);  // append the button below to the grid content table         }     }, 0)}function Click(args) {        dotnetref.invokeMethodAsync('BtnClick'); // call C# method from javascript function}
 
kindly download the sample which we have prepared using above solution from below  
 
 
Refer our UG documentation from below  
  
 
Please get back to us if you have further queries.  
 
Regards, 
Vignesh Natarajan 


Marked as answer

LP Lukasz Pesik February 18, 2021 01:55 PM UTC

Hello,
Thanks for your reply. Is implementation presented by you, same on the blazor webassembly app? I cannot adapt it into my client-side app.
Thanks in advance 


LP Lukasz Pesik February 18, 2021 02:15 PM UTC

Hi again Vignesh
I handled with problem from my previous question. I have added "<script src="/renderbtn.js"></script>" into index.html file, and now everything works fine. Thanks for your help!


VN Vignesh Natarajan Syncfusion Team February 19, 2021 03:25 AM UTC

Hi Lukasz,  

Thanks for the update.  

We are glad to hear that you have achieved your requirement using our solution.  

Kindly get back to us if you have further queries.  

Regards, 
Vignesh Natarajan  


Loader.
Up arrow icon