We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Custom validation function for full column

How can I apply a custom validation function for a full column in javascript spreadsheet.

I am not quite sure how to properly format the excelObj.XLValidate.applyDVRules

Thank you.


3 Replies

VK Vinoth Kumar Sundara Moorthy Syncfusion Team September 17, 2019 11:20 PM

Hi Todd, 
 
Thank you for contacting Syncfusion support. 
 
We have checked your requirement and you can apply validation to entire column by specifying range in applyDVRules method in Spreadsheet. Please check the below link for more details about applyDVRules method, 
 
 
 
 
Could you please check the above details and get back to us if you need any further assistance on this? 
 
Regards, 
Vinoth Kumar S 



TH Todd Hoyle September 18, 2019 06:08 AM

Thank you for your reply.
I had already read those articles and samples.

I don't see how to define an entire row as having a validation rule, just ranges. In the demo, it is only applying to rows 1-15. If I add a new row on 16 it doesn't have the validation. Do I need to place event handlers that extend validation to new rows as they are added? versus stating this entire column has this validation?
If so what might that look like? 

I also only see the built in validations being shown here. Not a custom one. For example I need to validate one cell based on content in another cell. I have a function written to do the validation, I am just not sure how to pass it into the applyDVRules function.

Thanks
Todd



VK Vinoth Kumar Sundara Moorthy Syncfusion Team September 20, 2019 05:56 AM

Hi Todd, 
 
Query #1: I don't see how to define an entire row as having a validation rule 
 
We would like to let you know that your requirement can be achieved by using selectRow method. Please find the below code snippet, 
 
Code Snippet 
function fun() { 
    var xlObj = $("#Spreadsheet").ejSpreadsheet("instance"); 
    xlObj.XLValidate.applyDVRules(xlObj.XLSelection.selectRow(1), ["Between", "15", "20"], "number", true, true); 
} 
 
Query #2:  I add a new row on 16, the validation should be maintained 
 
We have checked your requirement and as per our current behavior, when you have inserted the row between the validation applied range then it will be maintained. We have achieved your requirement in the actionComplete event. Please find the below code snippet, 
 
Code Snippet 
function actionComplete(args) { 
    if (args.action == "insertRow") { 
        var xlObj = $("#Spreadsheet").ejSpreadsheet("instance"), range, splitData, rule, rng, options, fillRange; 
        rule = xlObj.XLEdit.getPropertyValue(args.startCell.rowIndex - 1, args.startCell.colIndex, "rule", args.sheetIndex); 
        splitData = rule.customVal.split("_"); 
        rng = this.getRangeIndices((splitData[1] === "list") ? splitData[3] : splitData[6]); 
        range = this.getAlphaRange(rng[0], rng[1], rng[2], rng[3]); 
        fillRange = this.getAlphaRange(rng[2] + 1, rng[1], rng[2] + 1, rng[3]); 
        xlObj.XLSelection.selectRange(fillRange); 
        options = { dataRange: range, direction: "down", fillRange: fillRange, fillType: ej.Spreadsheet.AutoFillOptions.CopyCells } 
        xlObj.XLDragFill.autoFill(options); 
        xlObj.clearContents(fillRange); 
    } 
 
} 
function btnClick() { 
    var xlObj = $("#Spreadsheet").ejSpreadsheet("instance"); 
    xlObj.insertEntireRow(15, 16); 
} 
 
 
Please find the below sample link, 
 
Query 3: Need to validate one cell based on content in another cell. I have a function written to do the validation, I am just not sure how to pass it into the applyDVRules function. 
 
Could you please confirm whether you need formula based or cell based validation and its use case scenario? 
 
Regards, 
Vinoth Kumar S 


Loader.
Live Chat Icon For mobile
Up arrow icon