snipt

Ctrl+h for KB shortcuts

JavaScript

DataTable : Custom row number

1
2
3
4
5
6
$(document).ready( function() {
  $('#example').dataTable( {
    "aLengthMenu": [[25, 50, -1], [25, 50, "All"]],
    "iDisplayLength": 25
  });
});
https://snipt.net/embed/61d84d22f817d2d20cb822cbd11235db/
/raw/61d84d22f817d2d20cb822cbd11235db/
61d84d22f817d2d20cb822cbd11235db
js
JavaScript
6
2016-12-18T05:39:08
True
False
True
Oct 29, 2012 at 04:28 AM
/api/public/snipt/46646/
datatable-custom-row-number
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nx">$</span><span class="p">(</span><span class="nb">document</span><span class="p">).</span><span class="nx">ready</span><span class="p">(</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="nx">$</span><span class="p">(</span><span class="s1">&#39;#example&#39;</span><span class="p">).</span><span class="nx">dataTable</span><span class="p">(</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="s2">&quot;aLengthMenu&quot;</span><span class="o">:</span> <span class="p">[[</span><span class="mi">25</span><span class="p">,</span> <span class="mi">50</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">25</span><span class="p">,</span> <span class="mi">50</span><span class="p">,</span> <span class="s2">&quot;All&quot;</span><span class="p">]],</span> </span><span id="L-4"><a name="L-4"></a> <span class="s2">&quot;iDisplayLength&quot;</span><span class="o">:</span> <span class="mi">25</span> </span><span id="L-5"><a name="L-5"></a> <span class="p">});</span> </span><span id="L-6"><a name="L-6"></a><span class="p">});</span> </span></pre></div> </td></tr></table>
DataTable

C#

Add new row to DataTable

1
2
3
4
5
6
7
DataRow newRow = datatable.NewRow();
newRow["equipCode"] = column1;
newRow["missingDate"] = column2;
datatable.Rows.Add(newRow);

// OR
datatable.Rows.Add(new object[] { column1.ToString(), column2.ToString() });
https://snipt.net/embed/a7217017322f817f923ba7da9d984d7c/
/raw/a7217017322f817f923ba7da9d984d7c/
a7217017322f817f923ba7da9d984d7c
csharp
C#
7
2019-06-17T01:21:22
True
False
False
/api/public/snipt/38631/
add-new-row-to-datatable
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">DataRow</span> <span class="n">newRow</span> <span class="p">=</span> <span class="n">datatable</span><span class="p">.</span><span class="n">NewRow</span><span class="p">();</span> </span><span id="L-2"><a name="L-2"></a><span class="n">newRow</span><span class="p">[</span><span class="s">&quot;equipCode&quot;</span><span class="p">]</span> <span class="p">=</span> <span class="n">column1</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a><span class="n">newRow</span><span class="p">[</span><span class="s">&quot;missingDate&quot;</span><span class="p">]</span> <span class="p">=</span> <span class="n">column2</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="n">datatable</span><span class="p">.</span><span class="n">Rows</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="n">newRow</span><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a> </span><span id="L-6"><a name="L-6"></a><span class="c1">// OR</span> </span><span id="L-7"><a name="L-7"></a><span class="n">datatable</span><span class="p">.</span><span class="n">Rows</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="k">new</span> <span class="kt">object</span><span class="p">[]</span> <span class="p">{</span> <span class="n">column1</span><span class="p">.</span><span class="n">ToString</span><span class="p">(),</span> <span class="n">column2</span><span class="p">.</span><span class="n">ToString</span><span class="p">()</span> <span class="p">});</span> </span></pre></div> </td></tr></table>
DataTable