Default.aspx
<ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True" AllowGrouping="True" AllowFiltering="True">
<Columns>
. . .
<ej:Column Field="AnswerID" HeaderText="RISPOSTA" ForeignKeyField="AnswerID"
ForeignKeyValue="AnswerValue" TextAlign="Left" Width="90" />
<ej:Column Field="Note" HeaderText="Note" TextAlign="Right" Width="75" >
<ValidationRule>
<ej:KeyValue Key="customCompare" Value="value"/> //assign custom validator function for Notes column
</ValidationRule>
</ej:Column>
</Columns>
</ej:Grid>
<script type="text/javascript">
$.validator.addMethod("customCompare", function (value, element, params) {
var gridObj = $("#OrdersGrid").ejGrid('instance');
var inx = gridObj.getIndexByRow($(this.currentForm).closest("tr")); //you can get the row with getIndexByRow
var data = gridObj.getDataByIndex(inx); //you can get the row Data using getDataByIndex
if (data.AnswerID)
return true;
return false;
}, "Note required");
</script> |
I tryed to use: if (data.answer == 0
&& (data.note == null || data.note =="")) instead of your : if (data.AnswerID)
Debugging the script i got the desired behaviour
but when I type something in the note editbox the value of data.note remain
blank so i can't pass the validation though i typed something in the note
cell.
So how can I catch the text typed in the inputbox?
Moreover i would like the inputbox of note to be 100% width of the cell and multiline; how can i do it?
Thanks in advance
<ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True"AllowGrouping="True" AllowFiltering="True">
<Columns>
. . .
<ej:Column Field="AnswerID" HeaderText="RISPOSTA"ForeignKeyField="AnswerID"
ForeignKeyValue="AnswerValue" TextAlign="Left"Width="90" />
<ej:Column Field="Note" HeaderText="Note" TextAlign="Right"Width="75" >
<ValidationRule>
<ej:KeyValue Key="customCompare" Value="value"/> //assign custom validator function for Notes column
</ValidationRule>
</ej:Column>
</Columns>
</ej:Grid>
<script type="text/javascript">
$.validator.addMethod("customCompare", function (value, element, params) {
var gridObj = $("#OrdersGrid").ejGrid('instance');
var inx = gridObj.getIndexByRow($(this.currentForm).closest("tr"));
var data = gridObj.getDataByIndex(inx);
if ((data.AnswerID === 0) && (value != null && value != "")) //Here get the required value of Note using value
return true;
else if (data.AnswerID === 0)
return false;
else
return true;
}, "Note required");
</script>
|
Default.aspx:-
<ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True" AllowGrouping="True" AllowFiltering="True">
<Columns>
. . .
<ej:Column Field="AnswerID" HeaderText="RISPOSTA" ForeignKeyField="AnswerID"
ForeignKeyValue="AnswerValue" TextAlign="Left" Width="90">
<ValidationRule>
<ej:KeyValue Key="customRegex" Value="value" /> // enable Validation for ForeignKey column
</ValidationRule>
</ej:Column>
<ej:Column Field="Note" HeaderText="Note" TextAlign="Right" Width="75">
<ValidationRule>
<ej:KeyValue Key="customCompare" Value="value" />
</ValidationRule>
</ej:Column>
</Columns>
<script type="text/javascript">
$.validator.addMethod("customRegex", function (value, element, params) {
var val = parseInt(value);
var gridObj = $("#OrdersGrid").ejGrid('instance');
var inx = gridObj.getIndexByRow($(this.currentForm).closest("tr"));
var data = gridObj.getDataByIndex(inx);
if (val == 1)
return true
else if ((val == 0) && (data.Note != null && data.Note != "")) // We can only set No when Note column is filled
return true
else
return false
}, "Please fill Note and then to change it into No");
</script> |
Default.aspx:-
<ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True" AllowGrouping="True" AllowFiltering="True">
<ClientSideEvents BeforeBatchSave="beforeBatchSave" />
<Columns>
. . .
<ej:Column Field="AnswerID" HeaderText="RISPOSTA" ForeignKeyField="AnswerID"
ForeignKeyValue="AnswerValue" TextAlign="Left" Width="90">
</ej:Column>
<ej:Column Field="Note" HeaderText="Note" TextAlign="Right" Width="75">
<ValidationRule>
<ej:KeyValue Key="customCompare" Value="value" />
</ValidationRule>
</ej:Column>
</Columns>
<script type="text/javascript">
function beforeBatchSave(args) {
args.batchChanges.changed.map(data => {
if ((data.AnswerID === 0) && (data.Note == null || data.Note == "")) {
alert('cannot save this record, please add note.')
args.cancel = true
}
})
}
</script> |
<ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True" AllowGrouping="True" AllowFiltering="True">
<ClientSideEvents BeforeBatchSave="beforeBatchSave" />
<Columns>
. . .
<ej:Column Field="AnswerID" HeaderText="RISPOSTA" ForeignKeyField="AnswerID"
ForeignKeyValue="AnswerValue" TextAlign="Left" Width="90">
</ej:Column>
<ej:Column Field="Note" HeaderText="Note" TextAlign="Right" Width="75">
<ValidationRule>
<ej:KeyValue Key="customCompare" Value="value" />
</ValidationRule>
</ej:Column>
</Columns>
<script type="text/javascript">
function beforeBatchSave(args) {
var err = [];
args.batchChanges.changed.map(data => {
if ((data.Verified === 0) && (data.EmployeeID == null || data.EmployeeID == "")) {
var id = data.OrderID;
err.push("Cannot save record please add not", id); //push the errors in the array and shown in one alert message
args.cancel = true
}
})
alert(err)
}
</script>
|
Default.aspx:-
<div id="confirmationDialog" style="display:none"> //Initialize Dialog
</div>
<ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True" AllowGrouping="True" AllowFiltering="True">
<ClientSideEvents BeforeBatchSave="beforeBatchSave" />
<Columns>
. . .
<ej:Column Field="AnswerID" HeaderText="RISPOSTA" ForeignKeyField="AnswerID"
ForeignKeyValue="AnswerValue" TextAlign="Left" Width="90">
</ej:Column>
<ej:Column Field="Note" HeaderText="Note" TextAlign="Right" Width="75">
<ValidationRule>
<ej:KeyValue Key="customCompare" Value="value" />
</ValidationRule>
</ej:Column>
</Columns>
<script type="text/javascript">
function beforeBatchSave(args) {
var err = [];
args.batchChanges.changed.map(data => {
if ((data.Verified === 0) && (data.EmployeeID == null || data.EmployeeID == "")) {
var id = data.OrderID;
err.push("Cannot save record please add not", id);
args.cancel = true
}
})
$("#confirmationDialog").ejDialog({ enableModal: true, width: 300, minHeight: 100, title: "AlertDialog" }); //Render Dialog (use proper Dialog id in the place of confirmationDialog)
$("#confirmationDialog").ejDialog("open"); //Open the Dialog using method
$("#confirmationDialog").ejDialog("setContent", err); //Set Alert content for Dialog
}
</script> |