LoginSignup
0
0

kintone テーブルの変更イベントで行位置を求める

Posted at

kintone テーブルの変更イベントには、テーブル行位置の情報が無いので、テーブル行位置を求めてみます。

概要

テーブルの変更イベント時の情報には、テーブル行のオブジェクトがあるので、テーブルの各行とオブジェクト比較を行うと、テーブル行位置を求めることができます。

例:
table[i] === event.changes.row

cybozu developer network レコード編集画面でフィールドの値を変更したときのイベント

changes.row オブジェクト 値を変更したテーブルの行データ
行を追加した場合:追加した行のデータ
行を削除した場合:「null」
テーブル外のフィールドを変更した場合:「null」

確認用アプリ

テーブル内項目を変更したら、テーブル行位置に行位置をセット

2023-12-29_13h08_55.png

操作例

変更した項目の行位置が、テーブル行位置と pos にセットされます。

2023-12-29_13h16_35.gif

確認用 JavaScript

.js
(function() {
  'use strict';
  const evs = [
    'app.record.create.change.テーブル',
    'app.record.create.change.文字列T',
    'app.record.create.change.数値T',
    'app.record.create.change.ユーザー選択T',
    'app.record.edit.change.テーブル',
    'app.record.edit.change.文字列T',
    'app.record.edit.change.数値T',
    'app.record.edit.change.ユーザー選択T'
    ]
  kintone.events.on(evs, function(event) {
    console.log('t1', event);
    let record = event.record;
    let table = record.テーブル.value;
    
    for (let i=0; i<table.length; i++) {
      if (table[i] === event.changes.row) {
        record.テーブル行.value = i;
        event.changes.row.value.pos.value = i;
        return event;
      }
    }
    
    record.テーブル行.value = '';
    return event;
  });
})();
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0