0

私はDevExpressのDevExtremeコントロール、特にDxDataGridを使用しています。グリッドの一般的な変数を作成して、各グリッドの設定を再利用します。

は今、私はDxDataGridを使用するたびに、私はこのような構成を指定する必要があります。

var grid = $("#myGrid").dxDataGrid({ 
    // These options need to be specified for each DxDataGrid 
    dataSource: { 
     ... 
    }, 
    columns: [ 
     ...     
    ], 
    editing: { 
     ...     
    }, 
    // The following options are always the same for every DxDataGrid 
    columnChooser: { 
     enabled: true 
    }, 
    allowColumnReordering: true, 
    sorting: { 
     mode: 'multiple' 
    }, 
    groupPanel: { 
     visible: true, 
     emptyPanelText: 'Blabla' 
    }, 
    pager: { 
     visible: true, 
     showNavigationButtons: true, 
     showInfo: true, 
     showPageSizeSelector: true, 
     allowedPageSizes: [10, 20, 50, 100] 
    }, 
    paging: { 
     pageSize: 10 
    }, 
    filterRow: { 
     visible: true 
    }, 
    searchPanel: { 
     visible: true, 
     placeholder: 'Buscar' 
    }, 
}).dxDataGrid('instance'); 

私は各DxDataGridに対して同一であり、すべての設定パラメータのためのコードの重複を避けるためにしたいと思います。次のようになりますquestion DevExpressのサポートメンバーは、次のように説明しました。

データグリッドの設定は、通常のJavaScriptオブジェクトです。 デフォルトのグリッド構成でオブジェクト変数を作成し、グリッドごとに を使用することができます。 jQuery.extend()関数を使用して、必要に応じて新規の オプション/プロパティをデフォルトの設定オブジェクトに追加します。

これを行う方法はわかりません。コードサンプルはありません。どんな助け?

答えて

1

例えば

var commonOptions = { 
    columnChooser: { 
     enabled: true 
    }, 
    allowColumnReordering: true, 
    .... 
}; 

とビューで

<script src="~/Scripts/DxDataGridCommonOptions.js"></script> // load the common options into the view 
var viewOptions = { 
    dataSource: { 
    .... // your view specific options 
    }, 
    .... 
}; 
var grid = $("#myGrid").dxDataGrid(
    $.extend(commonOptions, viewOptions) // merge the 2 sets of options 
).dxDataGrid('instance'); 
、あなたの一般的なオプションのグローバル変数が含まれている外部ファイルを作成します。
関連する問題