Articles in this section
Category / Section

How to validate record while adding in Gantt

1 min read

In Gantt control, it is possible to validate the fields provided by the user while adding or editing the data using actionBegin client side event. This event will be triggered with requestType argument as save before saving the data to Gantt, so at this point we can validate the fields with required condition.

The following code example explains the above scenario,

<div id="gantt"></div>    
    
<script type="text/javascript">
$("#gantt").ejGantt({
        dataSource: projectData,
        //...
        load: function (args) {
            var columns = this.getColumns();
            var column1 = {
                field: "ActualDate",
                headerText: "Actual Date",
                mappingName: "ActualDate",
                editType: "datepicker",
            },
                column2 = {
                    field: "EstimateDate",
                    headerText: "Estimate Date",
                    mappingName: "EstimateDate",
                    editType: "datepicker",
                }
 
            columns.splice(4, 0, column1, column2)
        },
        actionBegin: function (args) {
            if (args.requestType == "save") {
                if (Date.parse(args.data.ActualDate)>Date.parse(args.data.EstimateDate)) {
 
                    args.cancel = true;
                    window.alert("Actual Date should not be greater than Estimated Date");
                }
 
            }
        },
    });
</script>
 

The above example shows on how to validate the custom columns and alert the user if condition fails and cancel the add operation.

Sample link:

The simple sample to validate the Gantt fields while adding/ editing the data is available in the following link. Sample

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied