We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

BatchUpdate in ChildGrid Asp.net Core

Hello,
I have a scenario where I have a Grid with a child grid (like displayed below), all works well but I want to implement batchupdate in the childgrid. I can implement batchupdate in the main frid but not on the child, please help with an example of batchupdate in child grid. Thanks.

Yoab


@{
    var col = new List<Syncfusion.EJ2.Grids.GridAggregateColumn> {
new Syncfusion.EJ2.Grids.GridAggregateColumn(){ Field = "Cost", Format = "N2", Type = "sum", FooterTemplate = "Sum: ${sum}" }
};
}

@{

    var ChildGrid1 = new Syncfusion.EJ2.Grids.Grid()
    {
        DataSource = @prescr.GetAllS(),
        QueryString = "ProcessId",
        Aggregates = new List<Syncfusion.EJ2.Grids.GridAggregate> {
        new Syncfusion.EJ2.Grids.GridAggregate() {Columns = col} },
        Columns = new List<Syncfusion.EJ2.Grids.GridColumn>
{
        new Syncfusion.EJ2.Grids.GridColumn(){ Field="Drug", HeaderText="Drug Description", Width="80" },
        new Syncfusion.EJ2.Grids.GridColumn(){ Field="Notes", HeaderText="Posology", Width="200", TextAlign=Syncfusion.EJ2.Grids.TextAlign.Left },
        new Syncfusion.EJ2.Grids.GridColumn(){ Field="Quantity", HeaderText="Quantity", Width="80" },
        new Syncfusion.EJ2.Grids.GridColumn(){ Field="Cost", HeaderText="Cost (NGN)", Width="80", Format="N2" }
        }
    };
}
<div class="row">

    <div class="col-xl-12">

        <!--begin:: Widgets/Finance Summary-->
        <div class="kt-portlet kt-portlet--height-fluid">
            <div class="kt-portlet__head">
                <div class="kt-portlet__head-label">
                    <h3 class="kt-widget14__title">
                        Active Prescriptions
                    </h3>
                </div>
            </div>
            <div class="kt-portlet__body">
                <ejs-grid id="ProcessGridPharm" dataSource=@ViewBag.DataSource toolbarClick="toolbarClick" toolbar="@(new List<string>() { "ExcelExport" })" allowPaging="true" allowSorting="true" allowFiltering="true" childGrid="ChildGrid1" allowGrouping="false" gridLines="Both" allowTextWrap="true" load="load">
                    <e-grid-editSettings allowAdding="false" allowDeleting="false" allowEditing="false" showConfirmDialog="true" showDeleteConfirmDialog="true"></e-grid-editSettings>
                    <e-grid-textwrapsettings wrapMode="Both"></e-grid-textwrapsettings>
                    <e-grid-pagesettings pageSize="15"></e-grid-pagesettings>
                    <e-grid-filterSettings type="Excel"></e-grid-filterSettings>
                    <e-grid-columns>
                        <e-grid-column field="Id" width="40" headerText="Id" isPrimaryKey="true" isIdentity="true" visible="false"></e-grid-column>
                        <e-grid-column field="Patient" headertext="Patient" width="80"></e-grid-column>
                        <e-grid-column field="Clinician" headertext="Clinician" width="80"></e-grid-column>
                        <e-grid-column field="Department" headertext="Department" width="80"></e-grid-column>
                        <e-grid-column field="Notes" headertext="Notes" width="200"></e-grid-column>
                        <e-grid-column field="Service" headertext="Service" width="70"></e-grid-column>
                        <e-grid-column field="CreatedBy" headertext="Prescribed By" width="80"></e-grid-column>
                        <e-grid-column field="CreatedDate" headertext="Prescription Date" width="80"></e-grid-column>
                        <e-grid-column field="PatientsId" headertext="Patient" visible="false" width="80"></e-grid-column>
                        <e-grid-column field="ProcessId" headertext="Process Id" visible="false" width="80"></e-grid-column>
                        <e-grid-column headertext="Details" width="42" Template="<a rel='nofollow' href='/Patients/PatientDetails/?Id=${PatientsId}'class='btn btn-sm btn-secondary btn-icon'><i class='fa fa-user'></i></a>" allow-editing="false"></e-grid-column>
                    </e-grid-columns>
                </ejs-grid>
            </div>
            <!--end:: Packages-->
        </div>
    </div>
</div>

8 Replies

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team August 5, 2019 10:13 AM UTC

Hi Yoab,  

Thanks for contacting Syncfusion Support.  

We could see you are using a local data binding for the Child Data which is not recommended way for updating. So we suggest to use the UrlAdaptor with the DataManager for binding the batchUrl to the Grid. Refer to the following code example.  

@{ 
    var ChildGrid = new Syncfusion.EJ2.Grids.Grid() 
    { 
        DataSource = new Syncfusion.EJ2.DataManager() { Url = "UrlChildDataSource", BatchUrl = "batchUpdate", Adaptor = "UrlAdaptor" }, 
        QueryString = "EmployeeID", 
         . . . 
    }; 
} 
 
<div class="control-section"> 
    <ejs-grid id="HierarchyPrint" load="onLoad"> 
        <e-data-manager url="@Url.Action("UrlDatasource")" adaptor="UrlAdaptor"></e-data-manager> 
              . . . 
                  . . . 
    </ejs-grid> 
</div> 

In case, you would like to use only the local data binding for the child Grid with the batchUrl, you can use the RemoteSaveAdaptor. Refer to the following Help Document and Code example.  


@{ 
    var ChildGrid = new Syncfusion.EJ2.Grids.Grid() 
    { 
        DataSource = new Syncfusion.EJ2.DataManager() { json = "@ViewBag.dataSource", BatchUrl = "batchUpdate", Adaptor = "RemoteSaveAdaptor" }, 
        QueryString = "EmployeeID", 
    }; 
} 
 
<div class="control-section"> 
    <ejs-grid id="HierarchyPrint" load="onLoad"> 
        <e-data-manager url="@Url.Action("UrlDatasource")" adaptor="UrlAdaptor"></e-data-manager> 
             . . . 
                 . . . 
    </ejs-grid> 
</div> 

Regards,  
Seeni Sakthi Kumar S. 



YY Yoab Youssoufou August 5, 2019 12:58 PM UTC

Thanks a lot Seeni, but I still have a bug pls see attached pictures showing my controller code, view code as well as the error

Attachment: Batch_16b978a2.7z


SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team August 6, 2019 10:55 AM UTC

Hi Yoab,  

Thanks for your update.  

The reported issue has been caused due to the routing problem. Refer to the following code example with the Url Helper from the Razor syntax. 

 
@{ 
    var ChildGrid = new Syncfusion.EJ2.Grids.Grid() 
    { 
        DataSource = new Syncfusion.EJ2.DataManager() { 
            Url = Url.Action("UrlChildDataSource"), 
            BatchUrl = Url.Action("batchUpdate"), 
            Adaptor = "UrlAdaptor" 
        }, 
        QueryString = "EmployeeID",  
              . ..  
                    . .. 
    }; 
} 
 
<div class="control-section"> 
    <ejs-grid id="HierarchyPrint" childGrid="ChildGrid"> 
        <e-data-manager url="@Url.Action("UrlDatasource")" adaptor="UrlAdaptor"></e-data-manager> 
             . . .  
               . . .   
    </ejs-grid> 
</div> 

We have also prepared a sample that can be downloaded from the following location.  


Regards,  
Seeni Sakthi Kumar S. 



YY Yoab Youssoufou August 6, 2019 11:17 AM UTC

Perfect thanks


SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team August 6, 2019 01:19 PM UTC

Hi Yoab, 

Thanks for the update.  

We are happy to hear that your requirement has been resolved.  

Regards,  
Seeni Sakthi Kumar S. 



YY Yoab Youssoufou August 7, 2019 02:37 PM UTC

Hello one more thing. One of my columns in the childgrid is a boolean I want to represent with a check box. My code is below:
 @{
        var ChildGrid = new Syncfusion.EJ2.Grids.Grid()
        {
            DataSource = new Syncfusion.EJ2.DataManager()
            {
                Url = Url.Action("UrlChildDataSource"),
                BatchUrl = Url.Action("batchUpdate"),
                Adaptor = "UrlAdaptor"
            },
            QueryString = "ProcessId",
            Aggregates = new List<Syncfusion.EJ2.Grids.GridAggregate> {
            new Syncfusion.EJ2.Grids.GridAggregate() {Columns = col} },
            EditSettings = new Syncfusion.EJ2.Grids.GridEditSettings()
            {
                AllowAdding = true,
                AllowEditing = true,
                AllowDeleting = true,
                Mode = Syncfusion.EJ2.Grids.EditMode.Batch
            },
                Toolbar = new List<string>() { "Add", "Edit", "Delete", "Update", "Delete" },
            Columns = new List<Syncfusion.EJ2.Grids.GridColumn> {
                new Syncfusion.EJ2.Grids.GridColumn(){ Field="Id", Width="80", AllowEditing=false, Visible=false },
                new Syncfusion.EJ2.Grids.GridColumn(){ Field="ProcessId", Width="80", AllowEditing=false, Visible=false },
                new Syncfusion.EJ2.Grids.GridColumn(){ Field="DrugsId", HeaderText="Drug Description", Width="80", AllowEditing=false, Visible=false },
                new Syncfusion.EJ2.Grids.GridColumn(){ Field="Notes", HeaderText="Posology", Width="200", TextAlign=Syncfusion.EJ2.Grids.TextAlign.Left , AllowEditing=false},
                new Syncfusion.EJ2.Grids.GridColumn(){ Field="Quantity", HeaderText="Quantity", Width="80", AllowEditing=false },
                new Syncfusion.EJ2.Grids.GridColumn(){ Field="Cost", HeaderText="Cost", Width="80", Format="N2", AllowEditing=false },
                new Syncfusion.EJ2.Grids.GridColumn(){ Field="DispenseStatus", HeaderText="Dispensed?", DisplayAsCheckBox=true,  Width="60" }
    }
        };
    }

I also tried adding to the colum Type="Boolean", EditType="BooleanEdit" all to no avail, checkboxes are properly displayed but in editmode (adding or editing) the grid displays true or false I have recorded a short video as well as a screenshot attached. I wish to have a checkbox for editing. Thanks

Attachment: ChildGridBoolean_4e682043.7z


YY Yoab Youssoufou August 7, 2019 04:43 PM UTC

Please disregard problem solved, it was a simple syntax error "booleanedit" is supposed to be in all small letters, it can get confusing mixing pascal, camel and no cases

 new Syncfusion.EJ2.Grids.GridColumn(){ Field="DispenseStatus", HeaderText="Dispense?",EditType="booleanedit", DisplayAsCheckBox=true,  Width="60" }


SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team August 8, 2019 05:28 AM UTC

Hi Yoab, 

We are happy to hear that you are getting in the right direction. Please get back to us, if you require further assistance on this.  

Regards,  
Seeni Sakthi Kumar S. 


Loader.
Live Chat Icon For mobile
Up arrow icon