I want an Error to occur when the Update button on the DataGrid toolbar is clicked.

Hi, Syncfusion Teams.


When CRUD operation is performed on a grid with e-grid-editSettings with mode set to Normal, I want to generate an alert when the input is incorrect when returning from the controller.


I am trying to use cellSave mode, but it seems impossible in Normal mode. We would appreciate it if you could provide an alternative.


Below is the relevant code.


<ejs-grid id="AirSystemGrid" toolbar="toolbarItems" gridLines="Both" rowHeight="30" created="Created" cellSave="cellSave" allowTextWrap="true">
                <e-grid-textwrapsettings wrapMode="Header"></e-grid-textwrapsettings>
                <e-grid-editSettings allowAdding="true" allowEditing="true" allowDeleting="true" mode="Normal" newRowPosition="Bottom"></e-grid-editSettings>
                <e-grid-columns>
                    <e-grid-column field="AIR_SYS_NM" headerText="AIR SYSTEM" defaultValue="@empty" headerTextAlign="Center" textAlign="Left" ></e-grid-column>
                    <e-grid-column field="COOL_COIL" headerText="COOLING COIL LOAD (kW)" defaultValue="@empty" headerTextAlign="Center" textAlign="Right" width="80" validationRules="@(new { number=true })"></e-grid-column>
                    <e-grid-column field="HEAT_COIL" headerText="HEATING COIL LOAD (kW)" defaultValue="@empty" headerTextAlign="Center" textAlign="Right" width="80" validationRules="@(new { number=true })"></e-grid-column>
                    <e-grid-column field="SPL_AIR_FLRT" headerText="SUPPLY AIR FLOW RATE (L/S)" defaultValue="@empty" headerTextAlign="Center" textAlign="Right" width="80" validationRules="@(new { number=true })"></e-grid-column>
                    <e-grid-column field="FRS_AIR_FLRT" headerText="FRESH AIR FLOW RATE (L/S)" defaultValue="@empty" headerTextAlign="Center" textAlign="Right" width="80" validationRules="@(new { number=true })"></e-grid-column>
                    <e-grid-column field="ENT_DB" headerText="ENTERING DB" defaultValue="@empty" headerTextAlign="Center" textAlign="Right" width="80" validationRules="@(new { number=true })"></e-grid-column>
                    <e-grid-column field="ENT_WB" headerText="ENTERING WB" defaultValue="@empty" headerTextAlign="Center" textAlign="Right" width="80" validationRules="@(new { number=true })"></e-grid-column>
                    <e-grid-column field="LV_DB" headerText="LEAVING DB" defaultValue="@empty" headerTextAlign="Center" textAlign="Right" width="80" validationRules="@(new { number=true })"></e-grid-column>
                    <e-grid-column field="LV_WB" headerText="LEAVING WB" defaultValue="@empty" headerTextAlign="Center" textAlign="Right" width="80" validationRules="@(new { number=true })"></e-grid-column>
                    <e-grid-column field="SSB_COIL_LOAD" headerText="SENSIBLE COIL LOAD (kW)" defaultValue="@empty" headerTextAlign="Center" textAlign="Right" width="80" validationRules="@(new { number=true })"></e-grid-column>
                    <e-grid-column field="CHID_WT_FLRT" headerText="CHILLED WATER FLOW RATE (L/M)" defaultValue="@empty" headerTextAlign="Center" textAlign="Right" width="80" validationRules="@(new { number=true })"></e-grid-column>
                    <e-grid-column field="FLOR_AREA" headerText="FLOR AREA (m2)" defaultValue="@empty" headerTextAlign="Center" textAlign="Right" width="80" validationRules="@(new { number=true })"></e-grid-column>
                    <e-grid-column field="FMB" headerText="FAN MOTOR BHP" defaultValue="@empty" headerTextAlign="Center" textAlign="Right" width="80" validationRules="@(new { number=true })"></e-grid-column>
                    <e-grid-column field="FMK" headerText="FAN MOTOR KW" defaultValue="@empty" headerTextAlign="Center" textAlign="Right" width="80" validationRules="@(new { number=true })"></e-grid-column>
                </e-grid-columns>
            </ejs-grid>


function Created() {
            var AirSystemGrid = document.getElementById("AirSystemGrid").ej2_instances[0];
            var BLDGValue = document.getElementById("BldgNo").value;


            AirSystemGrid.dataSource = new ej.data.DataManager({
                url: "/HvacInform/HD_AirSystemURL?BldgNo=" + BLDGValue,
                crudUrl: "/HvacInform/HD_AirSystemCRUD?BldgNo=" + BLDGValue,
                adaptor: new ej.data.UrlAdaptor()
            });


            AirSystemGrid.refresh();
        }


        function cellSave() {
            alert("");
        }


public ActionResult HD_AirSystemURL([FromBody] DataManagerRequest dm, string BldgNo)
        {
            if (BldgNo == null) return Content("");
            HI_HD_ReportModel model = new HI_HD_ReportModel()
            {
                BLDG_SNO = BldgNo,
                AIR_SYS_NM =""
            };
            List<HI_HD_ReportModel> list = HI_HD_ReportModel.GetList(model,"S0");
            int listCnt = list.Count;


            return dm.RequiresCounts ? Json(new { result = list, count = listCnt }) : Json(list);
        }


        //HVAC Data Update
        public ActionResult HD_AirSystemCRUD([FromBody] CRUDModel<HI_HD_ReportModel> value, string BldgNo)
        {
            if (value == null) return Content("");
            int NamingCheck = value.Value.AIR_SYS_NM.Split('_').Length;
            if (NamingCheck == 1) return Content("ERROR");


            HI_HD_ReportModel model = new HI_HD_ReportModel();
            if (value.Action =="remove")
            {
                JObject jObj = (JObject)value.Key;
                string sAirSystem = jObj["AIR_SYS_NM"].ToString();
                model = new HI_HD_ReportModel()
                {
                    BLDG_SNO = BldgNo,
                    AIR_SYS_NM = sAirSystem
                };
            }
            else
            {
                /* Add & Update Model */
                model = new HI_HD_ReportModel()
                {
                    BLDG_SNO = BldgNo,
                    AIR_SYS_NM = value.Value.AIR_SYS_NM,
                    CHID_WT_FLRT = value.Value.CHID_WT_FLRT,
                    COOL_COIL = value.Value.COOL_COIL,
                    ENT_DB = value.Value.ENT_DB,
                    ENT_WB = value.Value.ENT_WB,
                    FLOR_AREA = value.Value.FLOR_AREA,
                    FRS_AIR_FLRT = value.Value.FRS_AIR_FLRT,
                    HEAT_COIL = value.Value.HEAT_COIL,
                    LV_DB = value.Value.LV_DB,
                    LV_WB = value.Value.LV_WB,
                    SPL_AIR_FLRT = value.Value.SPL_AIR_FLRT,
                    SSB_COIL_LOAD = value.Value.SSB_COIL_LOAD
                };
            }


            switch (value.Action)
            {
                case"insert":
                    HI_HD_ReportModel.REPORTDML(model,"I");
                    break;


                case"update":
                    HI_HD_ReportModel.REPORTDML(model,"U");
                    break;


                case"remove":
                    HI_HD_ReportModel.REPORTDML(model,"D");
                    break;
            }


            model = new HI_HD_ReportModel()
            {
                BLDG_SNO = BldgNo,
            };
            List<HI_HD_ReportModel> list = HI_HD_ReportModel.GetList(model,"S0");


            return Json(list);
        }


thanks.


1 Reply

RS Rajapandiyan Settu Syncfusion Team March 8, 2022 01:21 PM UTC

Hi Taewook, 

Thanks for contacting Syncfusion support. 

Before proceeding with your query we need more information on your requirement. So, kindly share the below details to provide a better solution. 

  1. Are you want to perform the validation at server side? What are the difficulties you have faced with Grid column-validation?
    https://ej2.syncfusion.com/aspnetcore/documentation/grid/editing/validation
  2. How could receive the error details at the client side? Are you throwing any exception from the server?
  3. Are you returning the plain text (“Error”) as response from server?

Regards, 
Rajapandiyan S 


Loader.
Up arrow icon