文章分類/

Infragistics|Ultimate UI IguiteUI|根據 igGrid 中的特定單元格值驗證輸入

尚無瀏覽量
2023-02-20 更新

infragistics log

通過使用igGrid的輸入驗證函數(igValidator),您可以根據特定單元格的值來驗證輸入。

     var editedCellRowID;
        $(function () {

            //igGrid
            $("#grid").igGrid({
                autoGenerateColumns: false,
                primaryKey: "ID",
                width: "auto",
              autoCommit: true,
                columns: [
                    { headerText: "ID", key: "ID", dataType: "number" },
                    { headerText: "数値", key: "Number", dataType: "number" },
                    { headerText: "最大値", key: "MaxNumber", dataType: "number" }
                ],
                dataSource: SampleData,
                features: [
                    {
                        name: "Updating",
                        editCellStarted: function(evt, ui){
                            // 対象行IDを取得
                            editedCellRowID = ui.rowID;
                        },
                        columnSettings: [ 
                            {
                                columnKey: "ID",
                                required: true,
                                readOnly: true,
                            },
                            {
                                columnKey: "Number",
                                required: true,
                                readOnly: false,
                                editorOptions:{
                                    validatorOptions: {
           // カスタム検証用メソッド
                                        custom: function (value, fieldOptions) {
                                            // 入力チェック
                                            // 同行の最大値を取得
                                            var maxValue = $("#grid").igGrid("getCellValue", editedCellRowID, "MaxNumber");
                                            if(maxValue < value){
                                                return false;
                                            }
                                            return true;
                                        },
                                        errorMessage : "MaxNumber より大きい値が設定されています。"
                                    }
                                }
                            },
                            {
                                columnKey: "MaxNumber",
                                editorOptions: {
                                    readOnly: true,
                                    disabled: false,
                                },
                            },
                        ]
                    }
                ]
            }); 

        });

執行結果

快速跳轉目錄

✦ 群昱 AccessSoft 你的全面軟體解決方案 ✦

身為全球眾多知名軟體在台灣合作夥伴,歡迎諮詢你需要的軟體服務!

Picture of 軟體專家
軟體專家

群昱作為全球知名軟體推薦合作夥伴,致力於提供更多軟體解決方案給你!

更多軟體新知

立即詢價

請留下完整資訊,以便我們提供精確的服務內容給你。

詢價資訊