Author Topic: Get another cell's value when use validation  (Read 5314 times)

noctrona

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 82
    • View Profile
Get another cell's value when use validation
« 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!

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Get another cell's value when use validation
« Reply #1 on: April 10, 2014, 08:16:42 am »
startdate can be fetched with ui.rowData[ dataIndx of startdate ]

noctrona

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 82
    • View Profile
Re: Get another cell's value when use validation
« Reply #2 on: April 10, 2014, 08:48:51 am »
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:

Code: [Select]
{ 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;
                                        }
                                    }
                                }
                          ]
                        }


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Get another cell's value when use validation
« Reply #3 on: April 10, 2014, 08:50:58 am »
What's your code in cellBeforeSave

noctrona

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 82
    • View Profile
Re: Get another cell's value when use validation
« Reply #4 on: April 10, 2014, 08:52:50 am »
What's your code in cellBeforeSave

The following
Code: [Select]
$("#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;
            }
        });

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Get another cell's value when use validation
« Reply #5 on: April 10, 2014, 09:17:30 am »
Pass rowIndx: ui.rowIndx to isValid function in cellBeforeSave and rowData would be available in validation callback fn.

noctrona

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 82
    • View Profile
Re: Get another cell's value when use validation
« Reply #6 on: April 10, 2014, 10:49:15 am »
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?


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Get another cell's value when use validation
« Reply #7 on: April 10, 2014, 12:32:40 pm »
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.