{"id":11055,"date":"2021-11-26T10:00:00","date_gmt":"2021-11-26T01:00:00","guid":{"rendered":"https:\/\/www.gigas-jp.com\/appnews\/?p=11055"},"modified":"2021-11-25T19:21:17","modified_gmt":"2021-11-25T10:21:17","slug":"javascript-handsontable-renderer-memo","status":"publish","type":"post","link":"https:\/\/www.gigas-jp.com\/appnews\/archives\/11055","title":{"rendered":"JavaScript HandSonTable Renderer Memo"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" src=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2021\/11\/Screen-Shot-2021-11-25-at-14.42.12.png\" alt=\"\" class=\"wp-image-11058\" width=\"789\" height=\"129\" \/><\/figure>\n\n\n\n<p>I would like to share about how to renderer as your desire cells when you use HandSonTable. HandSonTable can&#8217;t directly insert html elements into cells. But  after declaration <strong>renderer:html<\/strong><span class=\"has-inline-color has-vivid-cyan-blue-color\"> <\/span>in our table of cell, we can use html elements as your desire. Second ways is to create custom renderer in cells properties with our own way.<\/p>\n\n\n\n<p>Firstly we will create simple html file. In this file we will import handsontable.min.js and handsontable.min.css. We can get these file script from this site <a href=\"https:\/\/cdnjs.com\/libraries\/handsontable\">cdnjs.com<\/a>. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>&lt;script src=\"https:\/\/cdn.jsdelivr.net\/npm\/handsontable@11.0\/dist\/handsontable.full.min.js\"&gt;&lt;\/script&gt;\n&lt;link type=\"text\/css\" rel=\"stylesheet\" href=\"https:\/\/cdn.jsdelivr.net\/npm\/handsontable@11.0\/dist\/handsontable.full.min.css\" \/&gt;<\/strong><\/code><\/pre>\n\n\n\n<p>To insert our table, create a div with id attribute and call this id with JS <strong>querySelector<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>&lt;div id=\"example1\" class=\"hot \"&gt;&lt;\/div&gt;<\/strong>\n<strong>const container = document.querySelector('#example1');<\/strong><\/code><\/pre>\n\n\n\n<p><strong><span class=\"has-inline-color has-black-color\">Usage of HandSonTable<\/span><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>const hot = new Handsontable(container, {\ndata : data \n})<\/strong>;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>const data = &#091;\n    { id: 1, name: 'Suga', isActive: true, date: '2021-11-25' },\n    { id: 2, name: 'Jimin', isActive: false,  date: null },\n    { id: 3, name: 'JHope', isActive: true,  date: null },\n    { id: 4, name: 'V', isActive: false, date: null },\n  ];<\/strong><\/code><\/pre>\n\n\n\n<p>If you want to add <strong>colsHeader<\/strong>, set to true =&gt; <strong>colHeaders : true<\/strong><\/p>\n\n\n\n<p>And if you want to add strict cell type and render columns, we can set inside <strong>columns<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> <strong> columns: &#091;\n    { data: 'id', type: 'text' },\n    \/\/ 'text' is default, you don't actually need to declare it\n    { data: 'name', renderer: yellowRenderer },\n    \/\/ use default 'text' cell type but overwrite its renderer with yellowRenderer\n    { data: 'isActive', type: 'checkbox' },\n    { data: 'date', type: 'date', dateFormat: 'YYYY-MM-DD' },\n  ],<\/strong><\/code><\/pre>\n\n\n\n<p>I will add another custom renderer named with<strong> greenRenderer<\/strong> but this <strong>greenRenderer<\/strong> will not add all the cell, just add some row. So I will use this <strong>greenRenderer<\/strong> inside a cell.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong> cells(row, col, prop) {\n    if (row === 3 &amp;&amp; col === 0) {\n      this.renderer = greenRenderer;\n    }\n  }<\/strong><\/code><\/pre>\n\n\n\n<p><strong>yellowRenderer<\/strong> <strong>function<\/strong> =&gt; this function will add all the cell with background color yellow.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>const yellowRenderer = function(instance, td, row, col, prop, value, cellProperties) {\n  Handsontable.renderers.TextRenderer.apply(this, arguments);\n  td.style.backgroundColor = 'organe';\n};<\/strong><\/code><\/pre>\n\n\n\n<p><strong>greenRenderer<\/strong> <strong>function<\/strong> =&gt; this function will add some of cell with background color red.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>const greenRenderer = function(instance, td, row, col, prop, value, cellProperties) {\n  Handsontable.renderers.TextRenderer.apply(this, arguments);\n\n  td.style.backgroundColor = 'purple';\n}<\/strong>;\n<\/code><\/pre>\n\n\n\n<p>If you want to set custom colWidths , then set <strong>colWidths<\/strong> to your desire value.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>colWidths : 100<\/strong><\/code><\/pre>\n\n\n\n<p>Hope you enjoyed about this article!<\/p>\n\n\n\n<p>By Ami<\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/11055\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/https:\/\/www.gigas-jp.com\/appnews\/archives\/11055\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"JavaScript HandSonTable Renderer Memo\" data-hatena-bookmark-layout=\"standard\" title=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\"> <img src=\"\/\/b.hatena.ne.jp\/images\/entry-button\/button-only@2x.png\" alt=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\" width=\"20\" height=\"20\" style=\"border: none;\" \/><\/a><script type=\"text\/javascript\" src=\"\/\/b.hatena.ne.jp\/js\/bookmark_button.js\" charset=\"utf-8\" async=\"async\"><\/script><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/11055\" data-text=\"JavaScript HandSonTable Renderer Memo\" data-via=\"GIGASJAPAN_APPS\" data-lang=\"ja\">Tweet<\/a><\/div>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/11055\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_facebook_send\"><div id=\"fb-root\"><\/div><fb:send href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/11055\" colorscheme=\"light\" ><\/fb:send><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>I would like to share about how to renderer as your desire cells when you use HandSonTable. HandSonTable can&#038;# [&hellip;]<\/p>\n","protected":false},"author":19,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[100],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/11055"}],"collection":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/comments?post=11055"}],"version-history":[{"count":2,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/11055\/revisions"}],"predecessor-version":[{"id":11061,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/11055\/revisions\/11061"}],"wp:attachment":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/media?parent=11055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/categories?post=11055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/tags?post=11055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}