ParamQuery grid support forum
General Category => Help for ParamQuery Pro => Topic started by: noctrona on April 10, 2014, 08:04:04 am
-
Hi team,
I need a validation to compare startdate and enddate. So I add validation on enddate column. But with the validation function I can only get the current cell value by "ui.value". So how can I get the startdate cell's value in enddate's validation compare function?
Thank you!
-
startdate can be fetched with ui.rowData[ dataIndx of startdate ]
-
startdate can be fetched with ui.rowData[ dataIndx of startdate ]
Hi,
As I check by debug tool, the ui.rowData is undefined. Please have a look with my code:
{ title: "Start Date", width: 85,align: "center", dataIndx:"startDate",
editor: {type: dateEditor},
validations: [
{type: function (ui) {
var value = ui.value;
var currentStart = new Date(value.split('-')[0],value.split('-')[1],value.split('-')[2]);
var periodStart = new Date(sDate.split('-')[0],sDate.split('-')[1],sDate.split('-')[2]);
var periodEnd = new Date(eDate.split('-')[0],eDate.split('-')[1],eDate.split('-')[2]);
if(currentStart < periodStart){
ui.msg += 'Start Date must greater than this period start date!'
return false;
}
if(currentStart > periodEnd){
ui.msg += 'Start Date must less than this period end date!'
return false;
}
}
}
]
}
{ title: "End Date", width: 85,align: "center",dataIndx:"endDate",
editor: {type: dateEditor},
validations: [
{type: function (ui) {
var value = ui.value;
var date = ui.rowData; [b]// undefined[/b]
var currentEnd = new Date(value.split('-')[0],value.split('-')[1],value.split('-')[2]);
var periodStart = new Date(sDate.split('-')[0],sDate.split('-')[1],sDate.split('-')[2]);
var periodEnd = new Date(eDate.split('-')[0],eDate.split('-')[1],eDate.split('-')[2]);
if(currentEnd < periodStart){
ui.msg += 'End Date must greater than this period start date!'
return false;
}
if(currentEnd > periodEnd){
ui.msg += 'End Date must less than this period end date!'
return false;
}
}
}
]
}
-
What's your code in cellBeforeSave
-
What's your code in cellBeforeSave
The following
$("#grid_json").on("pqgridcellbeforesave", function (evt, ui) {
var isValid = $("#grid_json").pqGrid("isValid", { dataIndx: ui.dataIndx, value: ui.newVal }).valid;
if (!isValid) {
$("#grid_json").find(".pq-editor-focus").css({ "border-color": "red" });
return false;
}
});
-
Pass rowIndx: ui.rowIndx to isValid function in cellBeforeSave and rowData would be available in validation callback fn.
-
Pass rowIndx: ui.rowIndx to isValid function in cellBeforeSave and rowData would be available in validation callback fn.
Hi,
Thanks for your help, it works now.
So the validation function on I add on column is the callback function about isValid.
Is that right?
-
Yes the validations originate from a call to isValid function.
row* (rowIndx, rowIndxPage or rowData) should be passed to isValid if rowData is required in validation callback function.