翻譯|使用教程|編輯:龔雪|2021-08-02 09:54:22.620|閱讀 428 次
概述:Kendo UI for jQuery中的Spreadsheet控件支持自定義單元格,本文將為大家介紹這個自定義單元格的編輯器及其使用。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
自定義編輯器便于用戶輸入正確的值。
例如,自定義編輯器允許用戶通過從日歷中選擇日期替代在單元格中輸入日期,此功能是通過使用日期標(biāo)準(zhǔn)應(yīng)用數(shù)據(jù)驗證并選擇顯示按鈕來顯示日歷復(fù)選框?qū)崿F(xiàn)的。另一個內(nèi)置編輯器用于列表驗證標(biāo)準(zhǔn),它顯示一個顯示允許值的彈出窗口。
要定義自定義編輯器,請使用 kendo.spreadsheet.registerEditor(name, editor)。 該名稱是您選擇的 ID,稍后將使用它來選擇范圍上的此特定編輯器。 編輯器可以是一個對象或一個函數(shù),作為一個對象,它當(dāng)前應(yīng)該有一個edit方法和icon屬性,如下所述。
icon 屬性是一個字符串,其中包含要應(yīng)用于下拉按鈕的 CSS 類名稱。
當(dāng)編輯器是一個函數(shù)時,它會在帶有這個編輯器的單元格顯示時第一次被調(diào)用。 它返回一個對象,如前一種情況——具有edit方法和icon屬性,結(jié)果被緩存,您可以使用這種方法將編輯器的初始化延遲到第一次需要時。
<div id="spreadsheet" style="width: 100%;"></div> <script> kendo.spreadsheet.registerEditor("color", function(){ var context, dlg, model; // Further delay the initialization of the UI until the `edit` method is // actually called, so here just return the object with the required API. return { edit: function(options) { context = options; open(); }, icon: "k-icon k-i-background" }; // This function actually creates the UI if not already there, and // caches the dialog and the model. function create() { if (!dlg) { model = kendo.observable({ value: "#000000", ok: function() { // This is the result when OK is clicked. // Invoke the callback with the value. context.callback(model.value); dlg.close(); }, cancel: function() { dlg.close(); } }); var el = $("<div data-visible='true' data-role='window' data-modal='true' data-resizable='false' data-title='Select color'>" + " <div data-role='flatcolorpicker' data-bind='value: value'></div>" + " <div style='margin-top: 1em; text-align: right'>" + " <button style='width: 5em' class='k-button' data-bind='click: ok'>OK</button>" + " <button style='width: 5em' class='k-button' data-bind='click: cancel'>Cancel</button>" + " </div>" + "</div>"); kendo.bind(el, model); // Cache the dialog. dlg = el.getKendoWindow(); } } function open() { create(); dlg.open(); dlg.center(); // If the selected cell already contains some value, reflect // it in the custom editor. var value = context.range.value(); if (value != null) { model.set("value", value); } } }); $(function() { $("#spreadsheet").kendoSpreadsheet({ sheetsbar: false, excel: { // Required to enable Excel Export in some browsers. proxyURL: "http://demos.telerik.com/kendo-ui/service/export" }, sheets: [{ rows: [{ cells: [ { value: "Select color:", bold: true }, { background: "#fef0cd", editor: "color" } ] }] }] }); }); </script>
定義編輯器后,您可以通過 API 將其應(yīng)用到任何單元格。
var sheet = spreadsheet.activeSheet(); sheet.range("A5").editor("color");
結(jié)果當(dāng)用戶選擇 A5 時,單元格旁邊會顯示一個顯示圖標(biāo)的按鈕。 單擊時,自定義顏色選擇器會彈出并允許用戶選擇顏色。
edit方法提供了完全的靈活性,例如您可以使用 Popup 小部件。如果您知道不會同時顯示兩個實例,請在每次調(diào)用編輯時緩存 UI 或創(chuàng)建一個新實例。 請注意,上面的示例是指模態(tài)對話框。
Kendo UI for jQuery是完整的jQuery UI組件庫,可快速構(gòu)建出色的高性能響應(yīng)式Web應(yīng)用程序。Kendo UI for jQuery提供在短時間內(nèi)構(gòu)建現(xiàn)在Web應(yīng)用程序所需要的一切,從多個UI組件中選擇,并輕松地將它們組合起來,創(chuàng)建出酷炫響應(yīng)式的應(yīng)用程序,同時將開發(fā)時間加快了50%。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都網(wǎng)