<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Afuwape sunday</title>
    <description>The latest articles on DEV Community by Afuwape sunday (@inlogic).</description>
    <link>https://dev.to/inlogic</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F397387%2F5725cd32-9e0b-4800-8f5e-c9948cfbabd6.jpg</url>
      <title>DEV Community: Afuwape sunday</title>
      <link>https://dev.to/inlogic</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/inlogic"/>
    <language>en</language>
    <item>
      <title>Responsive data table with podtablejs</title>
      <dc:creator>Afuwape sunday</dc:creator>
      <pubDate>Wed, 25 Aug 2021 23:45:03 +0000</pubDate>
      <link>https://dev.to/inlogic/responsive-data-table-with-podtablejs-1cg4</link>
      <guid>https://dev.to/inlogic/responsive-data-table-with-podtablejs-1cg4</guid>
      <description>&lt;p&gt;This post is about creating responsive datatable but before we proceed with the march ui designers and developers have evolve with ideas on creating a responsive table some of which are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;horizontal overflow on mobile&lt;/li&gt;
&lt;li&gt;Hiding some cells on mobile and more&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The above listed approach are some of the approach designers have evolve with in making tables responsive below i will show you the podtable approach. &lt;/p&gt;

&lt;p&gt;Enough of the talk lets head down to the coding aspect but wait what approach are we going to use to make the table responsive? i will explain that below.&lt;/p&gt;

&lt;h5&gt;
  
  
  How are we going to do it?
&lt;/h5&gt;

&lt;p&gt;We are going to make use of a plain javascript table library to make the table responsive but before we proceed with code lets look at the result.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Finlogicstudio%2Fpodtable%2Fdev%2Fexamples%2Fpodtablejs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Finlogicstudio%2Fpodtable%2Fdev%2Fexamples%2Fpodtablejs.png" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Lets begin With it
&lt;/h5&gt;

&lt;p&gt;If you want to get started quick check the github page here &lt;br&gt;
&lt;a href="https://github.com/inlogicstudio/podtable" rel="noopener noreferrer"&gt;https://github.com/inlogicstudio/podtable&lt;/a&gt; and don't forget star the repo or continue reading we begin by installing the library from npm i believe you know about npm; of course you should.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i podtable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After installing the package then we need to pull it in our page to use it. by including the css in the head and the javascript at the end of the body tag both of them are important.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, 
      &amp;lt;link rel="&lt;/span&gt;&lt;span class="na"&gt;stylesheet&lt;/span&gt;&lt;span class="err"&gt;"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"podtable/dist/podtable.css"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;                          
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"podtable/dist/podtable.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next we proceed with the table markup which needs to be structured well and it will include some few spices to make it look good.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A data-grid-colname attributes which value will be the name of the column&lt;/li&gt;
&lt;li&gt;An empty th, td for head and body element which will serve as control column
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;table&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"table"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"table"&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"100%"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;thead&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;tr&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;th&amp;gt;&lt;/span&gt;Firstname&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;th&amp;gt;&lt;/span&gt;Lastname&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
               ...
            &lt;span class="nt"&gt;&amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/thead&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;tbody&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;tr&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;td&lt;/span&gt; &lt;span class="na"&gt;data-grid-colname=&lt;/span&gt;&lt;span class="s"&gt;"Firstname"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Mark&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;td&lt;/span&gt; &lt;span class="na"&gt;data-grid-colname=&lt;/span&gt;&lt;span class="s"&gt;"Lastname"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Spencer&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
               ...
            &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/tbody&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/table&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First dont forget to style your table so as to make it look sweet but if you notice the html mark up we have a data-grid-colname attribute this will be use in the child row as the child item name also we have an empty th and td like i said earlier this will be the control toggle for the the row next we write the js that handles the magic for us&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;DOMContentLoaded&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Podtable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Podtable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#table&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code will instantiate the table library and what does the podtable library do open your browser and reload your page and reduce the size of your browser gradually and watch podtable hide  cells from the right when there are no more room to show it there are more option that can be passed to the podtable instance let see that below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;DOMContentLoaded&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Podtable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Podtable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#table&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;keepCell&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The keepCell option what does it do ? just like the name suggest its an array to specify the index of cells not to hide with the above code the second cell and the seventh cell wont be hidden you might be wondering why did i say second and and seventh cell and 1 &amp;amp; 6 is up in the code don't forget in programming the counting starts from 0.&lt;/p&gt;

&lt;p&gt;alright thats it here is the github link to read more &lt;br&gt; &lt;a href="https://github.com/inlogicstudio/podtable" rel="noopener noreferrer"&gt;https://github.com/inlogicstudio/podtable&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ui</category>
      <category>ux</category>
      <category>javascript</category>
      <category>datatable</category>
    </item>
  </channel>
</rss>
