失敗という言葉を使わない
糸川英夫・失敗の歴史
「人生で大切なのは、失敗の歴史である」
|
糸川英夫・夢を届ける
『自分にできること』よりも
『世の中が求めていること』に
挑戦しつづけたほうが人生も楽しい。
|
Tabulator 日本語化
ここで教えていただきました。
< コード例 >
locale: true, //trueならばブラウザの言語設定を自動検出 'ja'のように指定することも可能
langs: {
ja: {
//データ読込関連のテキストの翻訳
data: {
loading: '読込中',
error: 'エラー',
},
//ページネーション関連のテキストの翻訳
pagination: {
page_size: '表示件数',
page_title: 'ページを表示',
first: '最初',
first_title: '最初のページ',
last: '最後',
last_title: '最後のページ',
prev: '前',
prev_title: '前のページ',
next: '次',
next_title: '次のページ',
all: 'すべて',
counter: {
showing: '表示中',
of: '/',
rows: '件',
pages: 'ページ',
},
},
},
},
< 画面例 >
|
Tabulator のチャートを使ってみる
columns の formatter を progress にします。
< コード例 >
データはサーバー側で用意してます。
// パーセンテージプログレスバー //
{
title: "TTS Ratio", field: "PCNT_TTS", formatter: "progress", formatterParams: {
min: 0, // 範囲最小値
max: 100, // 範囲最大値
color: ["#008600"], // 棒グラフ色
legend: true, // 値表示 or not
legendColor: "#FFFFFF", // 値色
legendAlign: "justify", // 値位置
},
width: 100,
topCalc: "avg", bottomCalcParams: { precision: 1 },
/*formatter: function (cell, formatterParams, onRendered) {
return Math.round(cell.getValue() / 5)
},*/
}
< 画面例 >
過去1年分の為替レートの最大を100, 最小を0とした率を表示
Tabulator rowFormatterを使って、文字色を変化させる
Tabulator でカラムのformatter設定で文字色を変えたり、画像を表示したりできますが、列が多くなると見通しが悪くなるので、rowFormatterで同様の処理をしてみました。
< コード例 >
// @@ 行をフォーマットする時 @@ //
rowFormatter: (row) => {
// ++ 各行の列走査をしてエレメントを取得 ++ //
$.each($(row.getElement()).children(''), function (j, itm) {
// 属性に 'tabulator-field'がある場合 //
const fld = $(this).attr('tabulator-field');
// TTS前営業日差 //
if (fld === 'RT_TTS_LASTDIFF') {
const currDiff = row.getData().RT_TTS_LASTDIFF;
if (currDiff >= 0) {
$(this).text('+' + numeral(currDiff).format('#,###.#0'));
$(this).css('color', 'blue');
} else {
$(this).css('color', 'red');
}
}
// TTB前営業日差 //
if (fld === 'RT_TTB_LASTDIFF') {
const currDiff = row.getData().RT_TTB_LASTDIFF;
const currTTB = row.getData().RT_TTB;
if (currTTB <= 0) {
$(this).text("")
}
else {
if (currDiff >= 0) {
$(this).text('+' + numeral(currDiff).format('#,###.#0'));
$(this).css('color', 'blue');
} else {
$(this).css('color', 'red');
}
}
}
// セルの右罫線色変更 //
if (fld === 'CD_CURR' && $(this).text().length === 3) {
let curstyleV = $(this).attr('style');
curstyleV += 'border-right-color:#3c3c3c;';
$(this).attr('style', curstyleV);
}
// ドラッグドロップ行移動説明 //
if ($(this).hasClass("tabulator-row-handle")) {
$(this).attr('title', "ドラッグドロップしてこの行を移動出来ます");
$(this).addClass('tippydiv');
}
});
},
< 画面例 >
銀行発表の日次為替レート
前営業日より上がった場合、青文字、下がった場合赤文字。
|
|
Tabulator で 行クリックを動的発生させてメイン表と明細表を同時に表示させる
マスタリンクしている2表があってメインレコードをクリックして明細表を横やサブグリッドで表示することはよくあると思います。
メイン表を読み込んだ時点で明細表も同時に表示したくなり、
これもStackOverFlowで同様のことをしたい人を見つけ、回答を参考にして書いてみました。
< コード例 >
カラムには”id”の列が必要なので設定
“id”はサーバー側でセット済
{ field: "id", visible: false }
tableBuiltのイベントでメイン表の1行目をクリックさせる
// @@ 機材別合計テーブル生成時 @@ //
table.on("tableBuilt", function () {
// == 省略 == //
// == 1行目クリック == //
const fstrow = table.getRow(1) // <=== 合計計算行を上に配置したのでインデックスは1になる(と思う)
const fstrowelm = fstrow.getElement()
$(fstrowelm).trigger('click')
})
メインテーブルの行クリックイベント
// @@ メインテーブル行をクリックした時 @@ //
table.on("rowClick", function (e, row) {
//e - the click event object
//row - row component
// == 省略 == //
// -C 明細データリクエスト取得 //
const dlg = new OpeEqDialog()
let details = dlg.getModelDetails(al_icao, name)["rows"]
details.forEach((tmp, i) => {
if (OpeEqDialog.active_regnumbers.includes(tmp.nm_regist)) {
tmp.is_active = "*"
} else {
tmp.is_active = ""
}
tmp["id"] = i
})
console.log(details)
// 番号コード明細テーブル表示 //
dlg.showDetailTable(details, name)
})
< 画面例 >
1行目クリックを発生させない場合
明細テーブルが非表示
1行目クリックを発生させる
明細テーブルが表示される、更に明細テーブルにも同様の処理を追加して、機材の写真と登録履歴を横に表示
Tabulator で行に下線をつける
Tabulator でグループピングするまでもないものの、区切り線で分ければわかりやすくなるので、ソートされたカラムの値でグループで別れてる変わり目に区切り線をつけてみました。
< コード例 >
tableBuiltのリスナーで行を読み込んで下線を引く行にクラスを追加しています。
CSS
.border-bottom-blue1 {
border-bottom: solid 1px blue
}
JavaScript
// @@ tabulator テーブル生成完了時 @@ //
table.on('tableBuilt', function () {
console.log('--- data loaded ---')
console.log(new Date().getTime())
// テーブルの行を配列にする //
const rows = table.getRows()
// 日付変化下線用日付配列 //
let dates = []
rows.forEach((row) => {
dates.push(row.getData().subgDepDate)
})
console.log(dates)
// 日が変わる行のインデックス位置を配列にする //
let underlineIdxs = []
dates.forEach((dt, i) => {
if (i > 0 && dt !== dates[i - 1]) {
underlineIdxs.push(i - 1)
}
})
console.log(underlineIdxs)
// ++ 行を走査して下線位置に下線を引く ++ //
rows.forEach((row, i) => {
// 該当行の場合 //
if (underlineIdxs.includes(i)) {
const elm = row.getElement()
// 下線クラスを追加 //
$(elm).addClass("border-bottom-blue1")
}
})
})
< 画面例 >
スカイマークの飛行機の日付別運航履歴がわかりやすくなりました。
|
Tabulator でクリップボードにコピー
Tabulator に copyToClipboard メソッドがあり、特にDOMを操作しなくても出来ました。
方法は公式ドキュメントに詳しく書かれています。
< コード例 >
プロパティ
// ++ Tabulator ++ //
let table = new Tabulator("#altable", {
// クリップボード設定 //
clipboard: true,
clipboardCopyConfig: {
columnHeaders: true, //do not include column headers in clipboard output
columnGroups: false, //do not include column groups in column headers for printed table
rowGroups: false, //do not include row groups in clipboard output
columnCalcs: true, //do not include column calculation rows in clipboard output
dataTree: false, //do not include data tree in printed table
formatCells: false, //show raw cell values without formatter
},
// == 他は省略 == //
})
テーブル生成後のイベントでステータスバーにコピー用アイコンを配置して、クリックのリスナーを書いてます。
// @@ テーブル生成時 @@ //
table.on("tableBuilt", function () {
// コピーボタン挿入 //
const html = `<span id="clipbtn" class="ml-2 mr-2 curpo tippydiv"
title="Copy to clipboard all records">
<img src="Img/copy_64_darkgray.png" width="20"/>
</span>`
const ftcnts = $(".tabulator-footer-contents").eq(0)
$(ftcnts).prepend(html)
// @@ コピーボタンを押した時 @@ //
$("#clipbtn").on("click", function (e) {
table.copyToClipboard("all") //copy the currently selected rows to the clipboard
toastr.info("All records were copied to clipboard")
})
// tippy //
tippy('.tippydiv', {
placement: 'top',
animation: 'scale',
duration: 1000,
arrow: true
})
})
< 画面例 >
Tabulator で クリックした行の文字色を変えて強調
Tabulator でクリックした行の明細表を別テーブルで表示する時、メインテーブルのレコードが多い場合、どの行をクリックしたのかがわからなくなるのを防ぐ為にクリックした行の文字色を変えて強調させてみました。
< コード例 >
まずはテーブルが生成された時の行文字色を取得してクラス変数にセット
// @@ 明細テーブルが生成された時 @@ //
table.on("tableBuilt", function () {
const componentToHex = (c) => {
var hex = c.toString(16)
return hex.length == 1 ? "0" + hex : hex
}
const rgb2hex = (r, g, b) => {
console.log(r, g, b)
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b)
}
// セル文字色取得 //
const cell = table.getRow(1).getCell("code").getElement()
const style = window.getComputedStyle(cell)
const rgbcol = style.getPropertyValue('color')
const rgbtxt = rgbcol.replace("rgb(", "").replace(")", "").replaceAll(" ", "")
const rgbary = rgbtxt.split(",")
this.cellColorDetail = rgb2hex(rgbary[0], rgbary[1], rgbary[2],)
})
セルをクリックした時
// @@ テーブル行をクリックした時 @@ //
table.on("rowClick", function (e, row) {
//e - the click event object
//row - row component
// 全行文字色をテーブル生成時の文字色にして初期化 //
const rows = table.getRows()
rows.forEach(tmp => { tmp.getElement().style.color = this.cellColor })
// 強調 //
row.getElement().style.color = "#0000FF"
// == 以下省略 == //
})
return table
}
< 画面例 >
コメントを投稿するにはログインしてください。