{"id":426,"date":"2010-07-05T19:32:59","date_gmt":"2010-07-05T15:32:59","guid":{"rendered":"http:\/\/www.dhtmlx.com\/blog\/?p=426"},"modified":"2025-05-19T14:03:36","modified_gmt":"2025-05-19T11:03:36","slug":"editable-datagrid-for-ruby-on-rails-built-with-dhtmlxgrid","status":"publish","type":"post","link":"https:\/\/dhtmlx.com\/blog\/editable-datagrid-for-ruby-on-rails-built-with-dhtmlxgrid\/","title":{"rendered":"Editable Datagrid for Ruby on Rails Built with dhtmlxGrid"},"content":{"rendered":"<p><strong>NOTE: This tutorial is for RoR 2. <a href=\"#ror3\">Check RoR 3<\/a> if you use it.<\/p>\n<p>We&#8217;ve also posted an updated <a href=\"https:\/\/dhtmlx.com\/blog\/dhtmlxgrid-with-ruby-on-rails\/\">tutorial for Ruby on Rails 4<\/a>.<\/strong><\/p>\n<p>This tutorial will show you how to display tabular data in Ruby on Rails with <a href=\"\/\/dhtmlx.com\/docs\/products\/dhtmlxGrid\/\">grid js<\/a> library, dhtmlxGrid Standard Edition, which is available under GNU GPL. At the end, we will have a datagrid with in-line editing, sorting, and filtering, which loads its data from the server and saves it back to the database using Ruby on Rails.<\/p>\n<p>To illustrate, we will create a table of users. This is a very common task for nearly any web application. Working with RoR, we could use scaffolds, but they don&#8217;t work so well for navigation on large sets of data. Besides, dhtmlxGrid has client-side editing and filtering functionality, which can greatly simplify things. This is how our final grid will look:<\/p>\n<p><div id=\"attachment_429\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-429\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/07\/ready_grid.gif\" alt=\"dhtmlxGrid and RoR Example: Editable Ajax Grid\" title=\"dhtmlxGrid and RoR Example: Editable Ajax Grid\" width=\"600\" height=\"430\" class=\"size-full wp-image-429\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/07\/ready_grid.gif 600w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/07\/ready_grid-300x215.gif 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><p id=\"caption-attachment-429\" class=\"wp-caption-text\">dhtmlxGrid and RoR Example: Editable Ajax Grid<\/p><\/div><br \/>\n<!--more--><\/p>\n<p><strong>Setting the Environment<\/strong><\/p>\n<p>To start, we create DB migration for a table of users. It will have 3 fields for storing First Name, Last Name and Phone Number.  We will also create a couple of test records to see how the grid will look.<\/p>\n<div class=\"codecolorer-container ruby default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"ruby codecolorer\">ruby script<span class=\"sy0\">\/<\/span>generate migration create_users<br \/>\n<br \/>\n<span class=\"kw1\">class<\/span> CreateUsers <span class=\"sy0\">&lt;<\/span> <span class=\"re2\">ActiveRecord::Migration<\/span><br \/>\n&nbsp; <span class=\"kw1\">def<\/span> <span class=\"kw2\">self<\/span>.<span class=\"me1\">up<\/span><br \/>\n&nbsp; &nbsp; create_table <span class=\"re3\">:users<\/span> <span class=\"kw1\">do<\/span> <span class=\"sy0\">|<\/span>t<span class=\"sy0\">|<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.<span class=\"kw3\">string<\/span> <span class=\"re3\">:first_name<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.<span class=\"kw3\">string<\/span> <span class=\"re3\">:last_name<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.<span class=\"kw3\">string<\/span> <span class=\"re3\">:phone<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; t.<span class=\"me1\">timestamps<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">end<\/span><br \/>\n&nbsp; &nbsp; User.<span class=\"me1\">create<\/span><span class=\"br0\">&#40;<\/span> <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re3\">:first_name<\/span> <span class=\"sy0\">=&gt;<\/span> <span class=\"st0\">&quot;John&quot;<\/span>, <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re3\">:last_name<\/span> <span class=\"sy0\">=&gt;<\/span> <span class=\"st0\">&quot;Smit&quot;<\/span>, <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re3\">:phone<\/span> <span class=\"sy0\">=&gt;<\/span> <span class=\"st0\">&quot;555 198 877&quot;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; User.<span class=\"me1\">create<\/span><span class=\"br0\">&#40;<\/span> <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re3\">:first_name<\/span> <span class=\"sy0\">=&gt;<\/span> <span class=\"st0\">&quot;Stanislav&quot;<\/span>, <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re3\">:last_name<\/span> <span class=\"sy0\">=&gt;<\/span> <span class=\"st0\">&quot;Wolski&quot;<\/span>, <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re3\">:phone<\/span> <span class=\"sy0\">=&gt;<\/span> <span class=\"st0\">&quot;456 456 454&quot;<\/span><span class=\"br0\">&#41;<\/span> &nbsp; &nbsp;<br \/>\n&nbsp; <span class=\"kw1\">end<\/span><br \/>\n<br \/>\n&nbsp; <span class=\"kw1\">def<\/span> <span class=\"kw2\">self<\/span>.<span class=\"me1\">down<\/span><br \/>\n&nbsp; &nbsp; drop_table <span class=\"re3\">:users<\/span><br \/>\n&nbsp; <span class=\"kw1\">end<\/span><br \/>\n<span class=\"kw1\">end<\/span><br \/>\n<br \/>\nrake db:migrate<\/div><\/div>\n<p>Additionally we need to create a model and controller for our demo:<\/p>\n<div class=\"codecolorer-container ruby default codecolorer-noborder\" style=\"\"><div class=\"ruby codecolorer\">ruby script<span class=\"sy0\">\/<\/span>generate model user<br \/>\nruby script<span class=\"sy0\">\/<\/span>generate controller admin<\/div><\/div>\n<p>Now we are ready to start building the main part of the users table. <\/p>\n<p><strong>Loading Empty Grid<\/strong><\/p>\n<p>As I said, on the client side we will be using dhtmlxGrid. <\/p>\n<p>When you download the grid package, unzip it and copy the dhtmlxGrid\/codebase and dhtmlxDataProcessor\/codebase folders to the \/public\/javascript\/ folder of your demo application. The dhtmlxGrid package contains lots of examples and supporting materials which are not needed in the application, so we are taking only the code we need.<\/p>\n<p>After that we can add our first action in <strong>\/app\/controllers\/admin_controller.rb<\/strong>:<\/p>\n<div class=\"codecolorer-container ruby default codecolorer-noborder\" style=\"\"><div class=\"ruby codecolorer\"><span class=\"kw1\">class<\/span> AdminController <span class=\"sy0\">&lt;<\/span> ApplicationController<br \/>\n&nbsp; &nbsp; <span class=\"kw1\">def<\/span> view<br \/>\n&nbsp; &nbsp; <span class=\"kw1\">end<\/span><br \/>\n<span class=\"kw1\">end<\/span><\/div><\/div>\n<p>We also create the first view &#8211; the file <strong>\/app\/views\/admin\/view.rhtml<\/strong>:<\/p>\n<div class=\"codecolorer-container html4strict default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\"><span class=\"sc0\">&lt;!DOCTYPE HTML PUBLIC &quot;-\/\/W3C\/\/DTD HTML 4.01 Transitional\/\/EN&quot;<\/span><br \/>\n<span class=\"sc0\">&nbsp; &nbsp; &quot;http:\/\/www.w3.org\/TR\/html4\/loose.dtd&quot;&gt;<\/span><br \/>\n<span class=\"sc2\">&lt;<span class=\"kw2\">html<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">head<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">script<\/span> <span class=\"kw3\">src<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;\/javascripts\/codebase\/dhtmlxcommon.js&quot;<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/javascript&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">script<\/span> <span class=\"kw3\">src<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;\/javascripts\/codebase\/dhtmlxgrid.js&quot;<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/javascript&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">script<\/span> <span class=\"kw3\">src<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;\/javascripts\/codebase\/dhtmlxgridcell.js&quot;<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/javascript&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">link<\/span> <span class=\"kw3\">rel<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;stylesheet&quot;<\/span> <span class=\"kw3\">href<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;\/javascripts\/codebase\/dhtmlxgrid.css&quot;<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/css&quot;<\/span> <span class=\"kw3\">media<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;screen&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">link<\/span> <span class=\"kw3\">rel<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;stylesheet&quot;<\/span> <span class=\"kw3\">href<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;\/javascripts\/codebase\/skins\/dhtmlxgrid_dhx_skyblue.css&quot;<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/css&quot;<\/span> <span class=\"kw3\">media<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;screen&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">head<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">body<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">div<\/span> <span class=\"kw3\">id<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;grid_here&quot;<\/span> <span class=\"kw3\">style<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;width:600px; height:400px;&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">script<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/javascript&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var grid = new dhtmlXGridObject(&quot;grid_here&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.setImagePath(&quot;\/javascripts\/codebase\/imgs\/&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.setHeader(&quot;First name, Last name, Phone&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.setInitWidths(&quot;100,100,*&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.setSkin(&quot;dhx_skyblue&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.init();<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">input<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;button&quot;<\/span> <span class=\"kw3\">value<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;Add&quot;<\/span> <span class=\"kw3\">onclick<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;grid.addRow(grid.uid(),'new user')&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">input<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;button&quot;<\/span> <span class=\"kw3\">value<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;Delete&quot;<\/span> <span class=\"kw3\">onclick<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;grid.deleteSelectedRows()&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">body<\/span>&gt;<\/span><br \/>\n<span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">html<\/span>&gt;<\/span><\/div><\/div>\n<p>As you can see, this view doesn&#8217;t contain any active logic, it just loads js and css files and initializes JavaScript grid on the page. <\/p>\n<p>Some important points to note:<\/p>\n<ul style=\"font-size:13px;\">\n<li>setImagePath points to codebase\/imgs from the dhtmlxGrid package.<\/li>\n<li>setHeader defines the structure of the grid, so the client-side grid will have columns to show data from our Users table (columns First Name, Last Name, and Phone Number).<\/li>\n<li>setInitWidths command defines the widths of columns, and * as the width for the last column enables auto-size for this column.<\/li>\n<\/ul>\n<p>&nbsp;<br \/>\nAdd new route in the <strong>routes.rb<\/strong>:<\/p>\n<div class=\"codecolorer-container ruby default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"ruby codecolorer\">map.<span class=\"me1\">resource<\/span> <span class=\"re3\">:admin<\/span>, <br \/>\n&nbsp; &nbsp; <span class=\"re3\">:collection<\/span> <span class=\"sy0\">=&gt;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; <span class=\"re3\">:view<\/span> &nbsp; &nbsp; &nbsp; <span class=\"sy0\">=&gt;<\/span> <span class=\"re3\">:get<\/span>,<br \/>\n&nbsp; &nbsp; &nbsp; <span class=\"re3\">:dbaction<\/span> <span class=\"sy0\">=&gt;<\/span> <span class=\"re3\">:get<\/span>,<br \/>\n&nbsp; &nbsp; &nbsp; <span class=\"re3\">:data<\/span> &nbsp; &nbsp; &nbsp; &nbsp;<span class=\"sy0\">=&gt;<\/span> <span class=\"re3\">:get<\/span><br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><\/div><\/div>\n<p>Now, if you go to\t<strong>http:\/\/localhost:3000\/admin\/view<\/strong>, you will see something similar to the following:<\/p>\n<div id=\"attachment_428\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-428\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/07\/grid_empty.gif\" alt=\"dhtmlxGrid and RoR Example: Empty Grid\" title=\"dhtmlxGrid and RoR Example: Empty Grid\" width=\"600\" height=\"404\" class=\"size-full wp-image-428\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/07\/grid_empty.gif 600w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/07\/grid_empty-300x202.gif 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><p id=\"caption-attachment-428\" class=\"wp-caption-text\">dhtmlxGrid and RoR Example: Empty Grid<\/p><\/div>\n<p>This will be the structure of our table of users. <\/p>\n<p><strong>Filling Grid with Data<\/strong><\/p>\n<p>dhtmlxGrid can load its content from an XML data source, so loading data into the grid is pretty simple due to the ability of Rails to generate XML feeds. <\/p>\n<p>We will add one more action in <strong>\/app\/controller\/admin_controller.rb<\/strong>:<\/p>\n<div class=\"codecolorer-container ruby default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"ruby codecolorer\"><span class=\"kw1\">class<\/span> AdminController <span class=\"sy0\">&lt;<\/span> ApplicationController<br \/>\n&nbsp; &nbsp; <span class=\"kw1\">def<\/span> view<br \/>\n&nbsp; &nbsp; <span class=\"kw1\">end<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">def<\/span> data<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re1\">@users<\/span> = User.<span class=\"me1\">all<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">end<\/span><br \/>\n<span class=\"kw1\">end<\/span><\/div><\/div>\n<p>And also let\u2019s create one more view. The file is <strong>\/app\/views\/admin\/data.rxml<\/strong>:<\/p>\n<div class=\"codecolorer-container xml default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"xml codecolorer\">xml.instruct! :xml, :version=&gt;&quot;1.0&quot; <br \/>\n<br \/>\nxml.tag!(&quot;rows&quot;) do<br \/>\n&nbsp; &nbsp; @users.each do |user|<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; xml.tag!(&quot;row&quot;,{ &quot;id&quot; =&gt; user.id }) do<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xml.tag!(&quot;cell&quot;, user.first_name)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xml.tag!(&quot;cell&quot;, user.last_name)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xml.tag!(&quot;cell&quot;, user.phone)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; end<br \/>\n&nbsp; &nbsp; end<br \/>\nend<\/div><\/div>\n<p>The template has a .rxml extension because we will generate XML, not HTML. Inside the template we are outputting data from the Users table as XML. <\/p>\n<p>Our last step will be to add one more line to the code in the <strong>\/app\/views\/admin\/view.rhtml<\/strong> file:<\/p>\n<div class=\"codecolorer-container html4strict default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\">&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">script<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/javascript&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var grid = new dhtmlXGridObject(&quot;grid_here&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.setImagePath(&quot;\/javascripts\/codebase\/imgs\/&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.setHeader(&quot;First name, Last name, Phone&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.setInitWidths(&quot;100,100,*&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.setSkin(&quot;dhx_skyblue&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.init();<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.load(&quot;\/admin\/data&quot;); \/\/added !<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/span><\/div><\/div>\n<p>With this additional line, we&#8217;ve defined that the grid will load data from the XML feed we\u2019ve just created.<\/p>\n<p>Now our page at <strong>http:\/\/localhost:3000\/admin\/view<\/strong> is showing that the grid correctly loaded the initial set of data. <\/p>\n<div id=\"attachment_427\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-427\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/07\/grid_2records.gif\" alt=\"dhtmlxGrid and RoR Example: Load Records in Grid\" title=\"dhtmlxGrid and RoR Example: Load Records in Grid\" width=\"600\" height=\"405\" class=\"size-full wp-image-427\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/07\/grid_2records.gif 600w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/07\/grid_2records-300x202.gif 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><p id=\"caption-attachment-427\" class=\"wp-caption-text\">dhtmlxGrid and RoR Example: Load Records in Grid<\/p><\/div>\n<p><strong>Saving Grid Data<\/strong><\/p>\n<p>Showing data in the grid was pretty easy, but it is useless without the ability to edit and save changes done by users when they edit grid records in the browser. <\/p>\n<p>Fortunately, dhtmlxGrid has a special extension, DataProcessor, which is available in the grid package and allows you to synchronize client-side data changes with the server-side database. To &#8220;switch on&#8221; the DataProcessor extension, we need to implement one more action. In <strong>\/app\/controllers\/admin_controller.rb<\/strong>:<\/p>\n<div class=\"codecolorer-container ruby default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"ruby codecolorer\"><span class=\"kw1\">class<\/span> AdminController <span class=\"sy0\">&lt;<\/span> ApplicationController<br \/>\n&nbsp; &nbsp; <span class=\"kw1\">def<\/span> view<br \/>\n&nbsp; &nbsp; <span class=\"kw1\">end<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">def<\/span> data<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re1\">@users<\/span> = User.<span class=\"me1\">all<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">end<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">def<\/span> dbaction<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">#called for all db actions<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; first_name = params<span class=\"br0\">&#91;<\/span><span class=\"st0\">&quot;c0&quot;<\/span><span class=\"br0\">&#93;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; last_name &nbsp; &nbsp;= params<span class=\"br0\">&#91;<\/span><span class=\"st0\">&quot;c1&quot;<\/span><span class=\"br0\">&#93;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; phone &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= params<span class=\"br0\">&#91;<\/span><span class=\"st0\">&quot;c2&quot;<\/span><span class=\"br0\">&#93;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re1\">@mode<\/span> = params<span class=\"br0\">&#91;<\/span><span class=\"st0\">&quot;!nativeeditor_status&quot;<\/span><span class=\"br0\">&#93;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re1\">@id<\/span> = params<span class=\"br0\">&#91;<\/span><span class=\"st0\">&quot;gr_id&quot;<\/span><span class=\"br0\">&#93;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">case<\/span> <span class=\"re1\">@mode<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">when<\/span> <span class=\"st0\">&quot;inserted&quot;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user = User.<span class=\"me1\">new<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user.<span class=\"me1\">first_name<\/span> = first_name<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user.<span class=\"me1\">last_name<\/span> = last_name<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user.<span class=\"me1\">phone<\/span> = phone<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user.<span class=\"me1\">save<\/span>!<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re1\">@tid<\/span> = user.<span class=\"me1\">id<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">when<\/span> <span class=\"st0\">&quot;deleted&quot;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user=User.<span class=\"me1\">find<\/span><span class=\"br0\">&#40;<\/span>@id<span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user.<span class=\"me1\">destroy<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re1\">@tid<\/span> = <span class=\"re1\">@id<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">when<\/span> <span class=\"st0\">&quot;updated&quot;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user=User.<span class=\"me1\">find<\/span><span class=\"br0\">&#40;<\/span>@id<span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user.<span class=\"me1\">first_name<\/span> = first_name<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user.<span class=\"me1\">last_name<\/span> = last_name<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user.<span class=\"me1\">phone<\/span> = phone<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user.<span class=\"me1\">save<\/span>!<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re1\">@tid<\/span> = <span class=\"re1\">@id<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">end<\/span> <br \/>\n&nbsp; &nbsp; <span class=\"kw1\">end<\/span><br \/>\n<span class=\"kw1\">end<\/span><\/div><\/div>\n<p>We\u2019ve got quite a big piece of code compared to our previous steps. <\/p>\n<p>In our new dbaction method, we are doing the following:<\/p>\n<ul style=\"font-size:13px;\">\n<li>Getting parameters from the incoming request. We are using c0, c1 &#8230; cN parameters, which are related to the columns of grid: c0 &#8211; the first column, c1 &#8211; the second column, etc.<\/li>\n<li>Getting the type of operation: inserted, updated or deleted<\/li>\n<li>Getting the ID of a grid row<\/li>\n<\/ul>\n<p>&nbsp;<br \/>\nWhen we have all the above info, the code executes logic for each operation: it adds a new user for &#8220;inserted&#8221;; it deletes and updates user info for &#8220;deleted&#8221; and &#8220;inserted&#8221; operations.<\/p>\n<p>In addition to this action we need to create one more XML view, which will be a response to an update operation. In the file <strong>\/app\/views\/admin\/dbaction.rxml<\/strong>:<\/p>\n<div class=\"codecolorer-container xml default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"xml codecolorer\">xml.instruct! :xml, :version=&gt;&quot;1.0&quot; <br \/>\n<br \/>\nxml.tag!(&quot;data&quot;) do<br \/>\n&nbsp; &nbsp; xml.tag!(&quot;action&quot;,{ &quot;type&quot; =&gt; @mode, &quot;sid&quot; =&gt; @id, &quot;tid&quot; =&gt; @tid }) <br \/>\nend<\/div><\/div>\n<p>The &#8220;tid&#8221; parameter in the above code provides a new ID value, which can (and will) be changed after the insert operation. The grid creates a temporary ID for a new record, which needs to be changed with an actual ID after saving the grid data. <\/p>\n<p>The server-side part is ready, so we only need to point our grid to the dbaction feed.<br \/>\nIn <strong>\/app\/views\/admin\/view.rhtml<\/strong> we add:<\/p>\n<div class=\"codecolorer-container html4strict default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\"><span class=\"sc2\">&lt;<span class=\"kw2\">script<\/span> <span class=\"kw3\">src<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;\/javascripts\/codebase\/dhtmlxdataprocessor.js&quot;<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/javascript&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; ...<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">script<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/javascript&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var grid = new dhtmlXGridObject(&quot;grid_here&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.setImagePath(&quot;\/javascripts\/codebase\/imgs\/&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.setHeader(&quot;First name, Last name, Phone&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.setInitWidths(&quot;100,100,*&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.setSkin(&quot;dhx_skyblue&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.init();<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.load(&quot;\/admin\/data&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dp = new dataProcessor(&quot;\/admin\/dbaction\/&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dp.init(grid);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">input<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;button&quot;<\/span> <span class=\"kw3\">value<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;Add&quot;<\/span> <span class=\"kw3\">onclick<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;grid.addRow(grid.uid(),'new user')&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">input<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;button&quot;<\/span> <span class=\"kw3\">value<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;Delete&quot;<\/span> <span class=\"kw3\">onclick<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;grid.deleteSelectedRows()&quot;<\/span>&gt;<\/span><\/div><\/div>\n<p>With this code, we are:<\/p>\n<ul style=\"font-size:13px;\">\n<li>Including one more file, to activate DataProcessor<\/li>\n<li>Adding two JS lines to initialize DataProcessor, pointing it to the dbaction feed <\/li>\n<li>Adding buttons to add and delete rows in the grid<\/li>\n<\/ul>\n<p>&nbsp;<br \/>\nNow, if you try the application on <strong>http:\/\/localhost:3000\/admin\/view<\/strong>, you will see that all changes, as well as added and deleted records, are stored in the DB automatically.  <\/p>\n<p>The way to make &#8220;inserted&#8221; function to work is:<br \/>\n1. Click button. A new row with some default value will display in the bottom of the grid table.<br \/>\n2. Input real values in the cells of the new row in the grid table.<br \/>\nThe new row will be saved in to database table. Refresh the page, you will see all the changes you just made.<\/p>\n<p><strong>Extra Functionality<\/strong><\/p>\n<p>If you remember, we were going to create a sortable and filterable datagrid. This functionality can be achieved without changes in server-side logic. We enable client-side filtering and sorting by adding the next code to the <strong>\/app\/views\/admin\/view.rhtml<\/strong> file:<\/p>\n<div class=\"codecolorer-container html4strict default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\">&lt;<span class=\"kw2\">script<\/span> <span class=\"kw3\">src<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;\/javascripts\/codebase\/ext\/dhtmlxgrid_filter.js&quot;<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/javascript&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; ...<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &lt;<span class=\"kw2\">script<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/javascript&quot;<\/span> <span class=\"kw3\">charset<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span>&gt;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var grid <span class=\"sy0\">=<\/span> new dhtmlXGridObject<span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;grid_here&quot;<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.setImagePath<span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;\/javascripts\/codebase\/imgs\/&quot;<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.setHeader<span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;First name, Last name, Phone&quot;<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.attachHeader<span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;#text_filter,#text_filter,#text_filter&quot;<\/span><span class=\"br0\">&#41;<\/span>; <span class=\"sy0\">\/\/<\/span>added !<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid.setColSorting<span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;str,str,str&quot;<\/span><span class=\"br0\">&#41;<\/span>;&nbsp; <span class=\"sy0\">\/\/<\/span>added !<\/div><\/div>\n<p>Finally, we have a datagrid which uses client-side logic to perform sorting and filtering of data, and manages data communication with a Ruby on Rails backend. <\/p>\n<div id=\"attachment_429-2\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-429-2\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/07\/ready_grid.gif\" alt=\"dhtmlxGrid and RoR Example: Editable Grid\" title=\"dhtmlxGrid and RoR Example: Editable Grid\" width=\"600\" height=\"405\" class=\"size-full wp-image-427\" \/><p id=\"caption-attachment-429-2\" class=\"wp-caption-text\">dhtmlxGrid and RoR Example: Editable Grid<\/p><\/div>\n<p>By clicking on the header you can sort the grid by any column. Typing text in input fields in the header will filter the grid records by entered text. When you edit records in the grid, the changes will be saved in the database automatically, as well as row addition and deletion (use the buttons below the grid). <\/p>\n<p><a name=\"ror3\"><strong>Modifications for Ruby on Rails 3 Integration<\/strong><\/a><\/p>\n<p><strong>1.<\/strong> In <b>routes.rb<\/b>:<\/p>\n<div class=\"codecolorer-container ruby default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"ruby codecolorer\">resource <span class=\"re3\">:admin<\/span> <span class=\"kw1\">do<\/span><br \/>\n&nbsp; &nbsp; collection <span class=\"kw1\">do<\/span><br \/>\n&nbsp; &nbsp; &nbsp; get <span class=\"st0\">'view'<\/span><br \/>\n&nbsp; &nbsp; &nbsp; get <span class=\"st0\">'data'<\/span><br \/>\n&nbsp; &nbsp; &nbsp; get <span class=\"st0\">'dbaction'<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">end<\/span><br \/>\n&nbsp; <span class=\"kw1\">end<\/span><\/div><\/div>\n<p><strong>2.<\/strong> Rename files:<\/p>\n<ul>\n<li>data.rxml to data.xml.builder<\/li>\n<li>dbaction.rxml to dbaction.xml.builder<\/li>\n<\/ul>\n<p>&nbsp;<br \/>\n<strong>3.<\/strong> Replace:<\/p>\n<div class=\"codecolorer-container ruby default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"ruby codecolorer\">grid.<span class=\"kw3\">load<\/span><span class=\"br0\">&#40;<\/span>\u201d<span class=\"sy0\">\/<\/span>login<span class=\"sy0\">\/<\/span>data\u201d<span class=\"br0\">&#41;<\/span>;<\/div><\/div>\n<p>with:<\/p>\n<div class=\"codecolorer-container ruby default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"ruby codecolorer\">grid.<span class=\"kw3\">load<\/span><span class=\"br0\">&#40;<\/span>\u201d<span class=\"sy0\">\/<\/span>login<span class=\"sy0\">\/<\/span>data.<span class=\"me1\">xml<\/span>\u201d<span class=\"br0\">&#41;<\/span>;<\/div><\/div>\n<p><strong>4.<\/strong> Replace:<\/p>\n<div class=\"codecolorer-container ruby default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"ruby codecolorer\">dp = new dataProcessor<span class=\"br0\">&#40;<\/span>\u201d<span class=\"sy0\">\/<\/span>login<span class=\"sy0\">\/<\/span>dbaction<span class=\"sy0\">\/<\/span>\u201d<span class=\"br0\">&#41;<\/span>;<\/div><\/div>\n<p>with:<\/p>\n<div class=\"codecolorer-container ruby default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"ruby codecolorer\">dp = new dataProcessor<span class=\"br0\">&#40;<\/span>\u201d<span class=\"sy0\">\/<\/span>login<span class=\"sy0\">\/<\/span>dbaction.<span class=\"me1\">xml<\/span>\u201d<span class=\"br0\">&#41;<\/span>;<\/div><\/div>\n<p>&nbsp;<br \/>\n<strong>Settings for Rails 3.1<\/strong><\/p>\n<p>If you want to use dhtmlxGrid with Rails 3.1 with asset pipeline feature, here are the additional details:<\/p>\n<p><strong>1.<\/strong> Make sure that asset pipeline feature is enabled in config:<\/p>\n<p><strong>config\/application.rb<\/strong>:<\/p>\n<div class=\"codecolorer-container ruby default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"ruby codecolorer\"><span class=\"co1\"># Enable the asset pipeline<\/span><br \/>\n&nbsp; &nbsp; config.<span class=\"me1\">assets<\/span>.<span class=\"me1\">enabled<\/span> = <span class=\"kw2\">true<\/span><\/div><\/div>\n<p>2. Copy all files from &#8216;dhtmlxgrid\/codebase&#8217; to the corresponding folders of Rails application in the directory &#8216;vendor\/assets&#8217;:<\/p>\n<ul>\n<li>js files &#8211; copy in &#8216;vendor\/assets\/javascripts\/dhtmlx&#8217;<\/li>\n<li>css files &#8211; copy in &#8216;vendor\/assets\/stylesheets\/dhtmlx&#8217;<\/li>\n<li>images &#8211; copy in &#8216;vendor\/assets\/images\/dhtmlx&#8217;<\/li>\n<\/ul>\n<p>&nbsp;<br \/>\n<strong>3.<\/strong> Change the path to images in grid:<\/p>\n<div class=\"codecolorer-container ruby default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"ruby codecolorer\">grid.<span class=\"me1\">setImagePath<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;\/images\/dhtmlx\/imgs\/&quot;<\/span><span class=\"br0\">&#41;<\/span>;<\/div><\/div>\n<p>Here is the code sample for adding dhtmlxGrid files on a page:<\/p>\n<div class=\"codecolorer-container ruby default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"ruby codecolorer\">&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sy0\">&lt;%<\/span>= javascript_include_tag <span class=\"st0\">'dhtmlx\/dhtmlxcommon.js'<\/span> <span class=\"sy0\">%&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sy0\">&lt;%<\/span>= javascript_include_tag <span class=\"st0\">'dhtmlx\/dhtmlxgrid.js'<\/span> <span class=\"sy0\">%&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sy0\">&lt;%<\/span>= javascript_include_tag <span class=\"st0\">'dhtmlx\/dhtmlxgridcell.js'<\/span> <span class=\"sy0\">%&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sy0\">&lt;%<\/span>= javascript_include_tag <span class=\"st0\">'dhtmlx\/dhtmlxdataprocessor.js'<\/span> <span class=\"sy0\">%&gt;<\/span><br \/>\n<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sy0\">&lt;%<\/span>= stylesheet_link_tag <span class=\"st0\">'dhtmlx\/dhtmlxgrid.css'<\/span> <span class=\"sy0\">%&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sy0\">&lt;%<\/span>= stylesheet_link_tag <span class=\"st0\">'dhtmlx\/skins\/dhtmlxgrid_dhx_skyblue.css'<\/span> <span class=\"sy0\">%&gt;<\/span><\/div><\/div>\n<p>The image below shows an example of directory tree for dhtmlxGrid, when you use Rails 3.1 with assets pipeline feature.<\/p>\n<div id=\"attachment_1360\" style=\"width: 297px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1360\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/07\/dhtmlxgrid-treeview.PNG\" alt=\"dhtmlxGrid Files - Directory Tree\" title=\"dhtmlxGrid Files - Directory Tree\" width=\"287\" height=\"396\" class=\"size-full wp-image-1360\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/07\/dhtmlxgrid-treeview.PNG 287w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/07\/dhtmlxgrid-treeview-217x300.PNG 217w\" sizes=\"auto, (max-width: 287px) 100vw, 287px\" \/><p id=\"caption-attachment-1360\" class=\"wp-caption-text\">dhtmlxGrid Files - Directory Tree<\/p><\/div>\n<p><small>Posted by Stas Wolski<\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>NOTE: This tutorial is for RoR 2. Check RoR 3 if you use it. We&#8217;ve also posted an updated tutorial for Ruby on Rails 4. This tutorial will show &#8230;<\/p>\n","protected":false},"author":2,"featured_media":3804,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[71,1],"tags":[33,6,14,36],"class_list":["post-426","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","category-uncategorized","tag-all-posts","tag-dhtmlxgrid","tag-tips","tag-ruby-on-rails"],"_links":{"self":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/426","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/comments?post=426"}],"version-history":[{"count":3,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/426\/revisions"}],"predecessor-version":[{"id":9476,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/426\/revisions\/9476"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/media\/3804"}],"wp:attachment":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/media?parent=426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/categories?post=426"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/tags?post=426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}