How can I select the rows in the second table?


My problem is that I tried to select the rows that are in true,the grid mark them as selected, but they are not really take them that way.

<ej-grid id="AProductsGrid" allow-selection="true" allow-paging="true" allow-filtering="true" height="400" width="@("100%")" row-selected="rowSelected" row-deselected="rowDeselected" action-failure="updateFailure" action-complete="gridActionComplete" row-selecting="rowSelecting" locale="@(System.Globalization.CultureInfo.CurrentCulture.Name.ToString())" query-cell-info="queryCellInfo"> <e-edit-settings allow-editing="true" edit-mode="@(EditMode.Batch)"></e-edit-settings> <e-toolbar-settings show-toolbar="true" toolbar-items='@new List<string> {"update","cancel"}'></e-toolbar-settings> <e-page-settings page-size="500"></e-page-settings> <e-filter-settings filter-type="Excel" /> <e-columns> <e-column field="" type="checkbox" header-text="@Localizer["Select"].Value"></e-column> <e-column field="IdProduct" header-text="@Localizer["Id Product"].Value" text-align="Left" is-primary-key="true"></e-column> <e-column field="ProductNumber" header-text="@Localizer["Product Number"].Value" text-align="Left" allow-editing="false"></e-column> <e-column field="Description" header-text="@Localizer["Description"].Value" text-align="Left" allow-editing="false"></e-column> <e-column field="ProductValue" header-text="@Localizer["Value"].Value" allow-editing="false" format="{0:N2}"></e-column> <e-column field="PercentAvailable" header-text="@Localizer["Percent Available"].Value" allow-editing="false" format="{0:P2}"></e-column> <e-column field="Allocate" header-text="@Localizer["Allocate"].Value" visible="false"></e-column> </e-columns> </ej-grid> </div> <div id="divGrid" style="display:block"> <div id="divGrid_Label" style="display:none"> <h3>@Localizer["Available products"]</h3> </div> <ej-grid id="ProductsGrid" create="onGridCreate" allow-selection="true" allow-paging="true" allow-filtering="true" height="400" width="@("100%")" row-selected="rowSelected" row-deselected="rowDeselected" action-failure="updateFailure" action-complete="gridActionComplete" row-selecting="rowSelecting" locale="@(System.Globalization.CultureInfo.CurrentCulture.Name.ToString())" query-cell-info="queryCellInfo"> <e-filter-settings filter-type="Excel" /> <e-edit-settings allow-editing="true" edit-mode="@(EditMode.Batch)" show-confirm-dialog="true"></e-edit-settings> <e-toolbar-settings show-toolbar="true" toolbar-items='@new List<string> {"update","cancel"}'></e-toolbar-settings> <e-page-settings page-size="200"></e-page-settings> <e-columns> <e-column field="" type="checkbox" header-text="@Localizer["Select"].Value"></e-column> <e-column field="IdProduct" header-text="@Localizer["Id Product"].Value" text-align="Left" is-primary-key="true"></e-column> <e-column field="ProductNumber" header-text="@Localizer["Product Number"].Value" text-align="Left" allow-editing="false"></e-column> <e-column field="Description" header-text="@Localizer["Description"].Value" text-align="Left" allow-editing="false"></e-column> <e-column field="ProductValue" header-text="@Localizer["Value"].Value" allow-editing="false" format="{0:N2}"></e-column> <e-column field="PercentAvailable" header-text="@Localizer["Percent Available"].Value" allow-editing="false" format="{0:P2}"></e-column> <e-column field="Allocate" header-text="@Localizer["Allocate"].Value" visible="true"></e-column> </e-columns> </ej-grid>

-------------------------------------------------------------------------------------------------------------------------------------------------

 function changeIdPortfolioProduct(args) {
            var idPortfolioProduct = args.value;
            $("#selectedPortfolioProduct").value = idPortfolioProduct;
            var gridObj = $("#ProductsGrid").data("ejGrid");
            firstSelection = false;

            /* Datasource for available products grid */
            var dataManager = new ej.DataManager({
                url: "/Products/GetProducts?IdPortfolioProduct=" + idPortfolioProduct,
                batchUrl: "/Products/AllocationBatchUpdate?IdPortfolioProduct=" + idPortfolioProduct,
                adaptor: new ej.UrlAdaptor()
            });

            /* Datasource for allocated products grid */
            var allocatedDataManager = new ej.DataManager({
                url: "/Products/GetAllocatedProducts?IdPortfolioProduct=" + idPortfolioProduct,
                batchUrl: "/Products/AllocationBatchUpdate?IdPortfolioProduct=" + idPortfolioProduct,
                adaptor: new ej.UrlAdaptor()
            });

            var allocatedGridObj = $("#AProductsGrid").data("ejGrid");
            allocatedGridObj.dataSource(allocatedDataManager);
            //allocatedGridObj.refreshContent();

            var query = new ej.Query();
            query.addParams("IdPortfolioProduct", idPortfolioProduct);

            gridObj.element.ejWaitingPopup("show");
            var execute = dataManager.executeQuery(query) // executing query
                .done(function (e) {
                    gridObj.element.ejWaitingPopup("hide");
                });

            gridObj.dataSource(dataManager);

            $.getJSON("/PortfolioProducts/GetPortfolioProductAmounts?IdPortflioProduct=" + idPortfolioProduct, function (result) {
                $("#productAmountTB").ejNumericTextbox({ value: result.PortfolioProductAmount });
                $("#pendingAmountTB").ejNumericTextbox({ value: result.PendingAmount });
                $("#allocatedAmountTB").ejNumericTextbox({ value: result.AllocatedAmount });
                $("#availableAmount").val(result.AvailableAmount);
            });
}

--------------------------------------------------------------------------------------------------------------------------------------------------------------




2 Replies

NE Neider August 29, 2018 05:44 PM UTC

this is the code missing

function gridActionComplete(args) {

            if (args.requestType == "batchsave" && args.target != undefined) {

                firstSelection = true;

                if (args.target.id == "ProductsGrid") {

                    var allocatedGridObj = $("#AProductsGrid").data("ejGrid");

                    allocatedGridObj.refreshContent();

                } else if (args.target.id == "AProductsGrid") {

                    //Select all records

                    if (this._gridRecordsCount > 0) {

                        this.selectRows(0, this._gridRecordsCount - 1);

                        this.batchChanges.changed = new Array();

                    }

                    var GridObj = $("#ProductsGrid").data("ejGrid");

                    GridObj.refreshContent();

                }

                

                var idPortfolioProduct = $("#ddPortfolioProducts").val();

                $.getJSON("/PortfolioProducts/GetPortfolioProductAmounts?IdPortflioProduct=" + idPortfolioProduct, function (result) {

                    $("#productAmountTB").ejNumericTextbox({ value: result.PortfolioProductAmount });

                    $("#pendingAmountTB").ejNumericTextbox({ value: result.PendingAmount });

                    $("#allocatedAmountTB").ejNumericTextbox({ value: result.AllocatedAmount });

                });

            }


            if (args.requestType == "refresh" && args.target != undefined && args.target.id == "AProductsGrid") {

                //Select all records

                if (this._gridRecordsCount > 0) {

                    this.selectRows(0, this._gridRecordsCount - 1);

                    this.batchChanges.changed = new Array();

                }

                //Display portfolio amounts

                var idPortfolioProduct = $("#ddPortfolioProducts").val();

                $.getJSON("/PortfolioProducts/GetPortfolioProductAmounts?IdPortflioProduct=" + idPortfolioProduct, function (result) {

                    $("#productAmountTB").ejNumericTextbox({ value: result.PortfolioProductAmount });

                    $("#pendingAmountTB").ejNumericTextbox({ value: result.PendingAmount });

                    $("#allocatedAmountTB").ejNumericTextbox({ value: result.AllocatedAmount });

                });

            }

           


            if (args.requestType == "refresh" && args.target != undefined && args.target.id == "ProductsGrid") {

                

                 if (this._gridRecordsCount > 0) {

                    this.batchChanges.changed = new Array();


                    for (var i = 0; i < this._currentJsonData.length; i++) {

                       

                        if (this._currentJsonData[i].Allocate == true) {

                            

                            this.selectRows(i);

                            this.multiSelectCtrlRequest = true;

                            this.batchChanges.changed.push(this._currentJsonData[i]);

                            if (!this.changed) {

                                this.changed = true;


                            }

                        }


                    }

                }

            }           

            

        }



AS Alan Sangeeth S Syncfusion Team August 30, 2018 10:34 AM UTC

Hi Neider, 

Thanks for contacting Syncfusion support. 

As per your given detail we suspect that you want to select the records at initial render in grid based on Allocate field values. 

In your given code example, you have mention an empty string to the checkbox column field property so, we suggest you to set the “Allocate” field name for checkbox column field property. Because by default, checkbox get checked based on that field values in dataSource.  

Refer the below code example. 

[Index.cshtml] 

<ej-grid id="ProductsGrid" allow-paging="true" datasource="ViewBag.dataSource">    
  
        <e-columns> 
            <e-column field="Verified" type="checkbox" header-text="Select"></e-column> 
            <e-column field="OrderID" header-text="Id Product" text-align="Left" is-primary-key="true"></e-column> 
 
             --- 
 
            <e-column field="Verified" header-text="Allocate" type="string" ></e-column> 
        </e-columns> 
 
    </ej-grid> 



We have prepared a sample and it can be downloadable from the below location. 


Refer the screen shot. 

 

Refer the help documentation. 

   

Regards,
Alan Sangeeth S 


Loader.
Up arrow icon