Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
435
Setting a dynamic max value in an editor
posted

I have a grid that allows users to enter a payment amount, however I want the validator to allow up to the amount due. 

So consider the following column setting (code snipped for brevity)

update.ColumnSetting().ColumnKey("AmountToPay")
.EditorType(ColumnEditorType.Currency)
.Required(true)
.Validation(true)
.EditorOptions("button:'spin', maxValue:0"); // Is there anyway to set the max value equal to the value of another column called "AmountDue" which is also in the grid?

Parents
  • 6279
    Verified Answer
    posted

    Hi,

    You can acomplish your goal by hooking to the igGridUpdating's editCellStarted event and in it set the max value of the AmountToPay column based on the value of cell for the AmountDue column on the same row (getting that using the igGrid's getCellValue API method).

    Since you're using MVC, you need to use jQuery's live function in order to hook to the afore-mentioned event like so:

    $("#grid1").live("iggridupdatingeditcellstarted", function(evt, ui) {
        if(ui.columnKey == "AmountToPay") {
            $(ui.editor).igEditor("option", "maxValue", ui.owner.grid.getCellValue(ui.rowID, "AmountDue"));
        }
    });
    



    PS: Our help article on event handling will also help you understand the logic I'm using.
    PPS: I'm attaching a simple HTML page which shows this solution in action - feel free to download it and give it a go. 

    Cheers,
    Borislav

    t72496.zip
Reply Children
No Data