ドロップダウン日付時刻ピッカー

セルでドロップダウン日付時刻ピッカーを使用すると、日付や時刻を設定して入力できます。

<p>ドロップダウン日付時刻ピッカーはSpreadJSで利用可能なドロップダウンの一つで、ユーザーはスタイルで定義された日付時刻ピッカーにより日付時刻を簡単に選択できます。</p> <p>SpreadJSでは、8種類の組み込みドロップダウンメニューを使用でき、これは日付時刻ピッカーの機能を提供します。日付時刻ピッカーを開く前に、セルのスタイルでオプションデータを設定する必要があります。</p> <p>次のようなコードでドロップダウン日付時刻ピッカーを使用できます:</p> <pre><code class="hljs js language-js"> <span class="hljs-comment">// ドロップダウンアイコンをクリックして日付時刻ピッカーを開きます。 </span> <span class="hljs-keyword">var</span> style = <span class="hljs-keyword">new</span> GC.Spread.Sheets.Style(); style.cellButtons = [ { <span class="hljs-attr">imageType</span>: GC.Spread.Sheets.ButtonImageType.dropdown, <span class="hljs-attr">command</span>: <span class="hljs-string">"openDateTimePicker"</span>, <span class="hljs-attr">useButtonStyle</span>: <span class="hljs-literal">true</span>, } ]; style.dropDowns = [ { <span class="hljs-attr">type</span>: GC.Spread.Sheets.DropDownType.dateTimePicker, <span class="hljs-attr">option</span>: { <span class="hljs-attr">showTime</span>: <span class="hljs-literal">true</span>, } } ]; sheet.setStyle(<span class="hljs-number">2</span>, <span class="hljs-number">5</span>, style); <span class="hljs-comment">// ドロップダウンボタンをクリックではなく、コマンドで日付時刻ピッカーを開きます。</span> spread.commandManager().execute({<span class="hljs-attr">cmd</span>:<span class="hljs-string">"openDateTimePicker"</span>,<span class="hljs-attr">row</span>:<span class="hljs-number">2</span>,<span class="hljs-attr">col</span>:<span class="hljs-number">18</span>,<span class="hljs-attr">sheetName</span>:<span class="hljs-string">"Sheet1"</span>}); </code></pre> <p>以下のオプションを設定することで、日付時刻ピッカーの形式をカスタマイズできます:</p> <ul> <li><strong>showTime: boolean</strong> : カレンダーに時間部分を表示する必要があるかどうかを指定します。</li> <li><strong>calendarPage: CalendarPage</strong> : カレンダーのデフォルトの形式を指定します。指定できる値は年、月、日です。サンプル<code>calendarPage: GC.Spread.Sheets.CalendarPage.year</code>.</li> <li><strong>startDay: CalendarStartDay</strong> : カレンダーで開始する曜日(通常では日曜日または月曜日)を指定します。サンプル<code>startDay: GC.Spread.Sheets.CalendarStartDay.monday</code>.</li> </ul>
var spreadNS = GC.Spread.Sheets; window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss")); initSpread(spread); }; function initSpread(spread) { var sheet = spread.getSheet(0); sheet.suspendPaint(); // -------------------- Date Time Picker : showTime true --------------------- var showTimeStyle = new GC.Spread.Sheets.Style(); showTimeStyle.cellButtons = [ { imageType: GC.Spread.Sheets.ButtonImageType.dropdown, command: "openDateTimePicker", useButtonStyle: true, } ]; showTimeStyle.dropDowns = [ { type: GC.Spread.Sheets.DropDownType.dateTimePicker, option: { showTime: true } } ]; sheet.setText(1, 2, "Date Time Picker (showTime: true)"); sheet.setStyle(2, 5, showTimeStyle); sheet.setColumnWidth(5, 200, GC.Spread.Sheets.SheetArea.viewport); // -------------------- Date Time Picker : showTime False --------------------- var notShowTimestyle = new GC.Spread.Sheets.Style(); notShowTimestyle.cellButtons = [ { imageType: GC.Spread.Sheets.ButtonImageType.dropdown, command: "openDateTimePicker", useButtonStyle: true, } ]; notShowTimestyle.dropDowns = [ { type: GC.Spread.Sheets.DropDownType.dateTimePicker, option: { showTime: false } } ]; sheet.setText(20, 2, "Date Time Picker (showTime: false)"); sheet.setStyle(21, 5, notShowTimestyle); // -------------------- Date Time Picker : CalendarPage - Year --------------------- var calendarYearStyle = new GC.Spread.Sheets.Style(); calendarYearStyle.cellButtons = [ { imageType: GC.Spread.Sheets.ButtonImageType.dropdown, command: "openDateTimePicker", useButtonStyle: true, } ]; calendarYearStyle.dropDowns = [ { type: GC.Spread.Sheets.DropDownType.dateTimePicker, option: { showTime: true, calendarPage: GC.Spread.Sheets.CalendarPage.year, } } ]; sheet.setText(20, 8, "Date Time picker (calendarPage - Year)"); sheet.setStyle(21, 11, calendarYearStyle); sheet.setColumnWidth(11, 200, GC.Spread.Sheets.SheetArea.viewport); // -------------------- Date Time Picker : CalendarPage - Month --------------------- var calendarMonthStyle = new GC.Spread.Sheets.Style(); calendarMonthStyle.cellButtons = [ { imageType: GC.Spread.Sheets.ButtonImageType.dropdown, command: "openDateTimePicker", useButtonStyle: true, } ]; calendarMonthStyle.dropDowns = [ { type: GC.Spread.Sheets.DropDownType.dateTimePicker, option: { showTime: true, calendarPage: GC.Spread.Sheets.CalendarPage.month, } } ]; sheet.setText(1, 8, "Date Time picker (calendarPage - Month)"); sheet.setStyle(2, 11, calendarMonthStyle); sheet.resumePaint(); spread.commandManager().execute({cmd:"openDateTimePicker",row:2,col:5,sheetName:"Sheet1"}); // spread.commandManager().execute({cmd:"openDateTimePicker",row:2,col:11,sheetName:"Sheet1"}); // spread.commandManager().execute({cmd:"openDateTimePicker",row:21,col:11,sheetName:"Sheet1"}); // spread.commandManager().execute({cmd:"openDateTimePicker",row:21,col:5,sheetName:"Sheet1"}); }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta name="spreadjs culture" content="ja-jp" /> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/ja/purejs/node_modules/@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/ja/purejs/node_modules/@grapecity/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/ja/purejs/node_modules/@grapecity/spread-sheets-resources-ja/dist/gc.spread.sheets.resources.ja.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script> <script src="app.js" type="text/javascript"></script> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <div class="sample-tutorial"> <div id="ss" style="width:100%; height: 100%"></div> </div> </body> </html>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }