前提・実現したいこと
Handsontableを使用していますが、ボタン押下時にテーブルの行数と列数を取得し、全セルの値をチェックし、エラーがあれば、該当セルの背景色を赤色に塗り潰したいです。
発生している問題・エラーメッセージ
setCellMetaメソッドを使用して、該当セルにclassを設定させる方法を試みましたが、適用されませんでした。
classを設定させる方法ではなくても問題ないのですが、実現方法を教えていただけないでしょうか。
該当のソースコード
jsx
1import React, { Component } from 'react'; 2import { HotTable } from '@handsontable/react'; 3import 'handsontable/dist/handsontable.full.css'; 4 5class Test extends Component { 6 constructor(props) { 7 super(props); 8 this.hotTableComponent = React.createRef(); 9 this.hotSettings = { 10 columns: [ 11 { title: 'test' } 12 ], 13 colWidths: [ 100 ], 14 startCols: 1, 15 startRows: 10, 16 rowHeaders: true, 17 width: 965, 18 height: 400, 19 }; 20 }; 21 createClick = () => { 22 // 行数取得 23 const countRows = this.hotTableComponent.current.hotInstance.countRows(); 24 // 列数取得 25 const countCols = this.hotTableComponent.current.hotInstance.countCols(); 26 27 for (let intI = 0; intI < countRows; intI++) { 28 for (let intJ = 0; intJ < countCols; intJ++) { 29 let errComment = 'エラー'; 30 31 if (errComment) { 32 // ★ここでセルの背景色を変更させたいです 33 this.hotTableComponent.current.hotInstance.setCellMeta( 34 intI, 35 intJ, 36 'className', 37 this.hotTableComponent.current.hotInstance.getCellMeta(intI, intJ).className + ' err-style' 38 ); 39 } 40 } 41 } 42 }; 43 render() { 44 return ( 45 <div> 46 <HotTable 47 id="hot" 48 ref={this.hotTableComponent} 49 settings={this.hotSettings} 50 /> 51 <button onClick={this.createClick}>登録</button> 52 </div> 53 ); 54 } 55}
CSS
1.err-style { 2 background-color: #FF0000; 3}
補足情報(FW/ツールのバージョンなど)
"@handsontable/react": "^2.1.0",
"handsontable": "^6.2.2",
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。