ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Calculate Row total while Searching in jQuery DataTable plugin<p>Are you applying DataTable Plugin ?</p> <p>Please share your complete code and html.</p>https://www.aspforums.net:443/Threads/448511/Calculate-Row-total-while-Searching-in-jQuery-DataTable-plugin/https://www.aspforums.net:443/Threads/448511/Calculate-Row-total-while-Searching-in-jQuery-DataTable-plugin/Wed, 19 Dec 2018 02:00:51 GMTCalculate Row total while Searching in jQuery DataTable plugin<p>&nbsp;</p> <pre class="brush: html">string strtHeader = &#34;&#34;; string strCloseTableTag = &#34;&lt;/table&gt;&#34;; string strOpenTableTag = &#34;&lt;table class=&#39;hover compact order-column cell-border&#39; cellspacing=&#39;0&#39; width=&#39;100%&#39; id=&#39;sample_2&#39;&gt;&#34;; #region sql string for colno == 8 { strtHeader = &#34;&lt;thead&gt;&lt;tr&gt;&#34; + &#34;&lt;th&gt;S/No&lt;/th&gt;&#34; + &#34;&lt;th&gt;Staff ID&lt;/th&gt;&#34; + &#34;&lt;th&gt;Surname&lt;/th&gt;&#34; + &#34;&lt;th&gt;Othernames&lt;/th&gt;&#34; + &#34;&lt;th&gt;Course Fee&lt;/th&gt;&#34; + &#34;&lt;th&gt;Accomodation&lt;/th&gt;&#34; + &#34;&lt;th&gt;Transport&lt;/th&gt;&#34; + &#34;&lt;th&gt;Feeding&lt;/th&gt;&#34; + &#34;&lt;th&gt;Other Cost&lt;/th&gt;&#34; + &#34;&lt;th&gt;Total&lt;/th&gt;&#34; + &#34;&lt;/tr&gt;&lt;/thead&gt;&#34; + &#34;&lt;tfoot&gt;&lt;tr&gt;&#34; + &#34;&lt;th&gt;S/No&lt;/th&gt;&#34; + &#34;&lt;th&gt;Staff ID&lt;/th&gt;&#34; + &#34;&lt;th&gt;Surname&lt;/th&gt;&#34; + &#34;&lt;th&gt;Othernames&lt;/th&gt;&#34; + &#34;&lt;th&gt;Course Fee&lt;/th&gt;&#34; + &#34;&lt;th&gt;Accomodation&lt;/th&gt;&#34; + &#34;&lt;th&gt;Transport&lt;/th&gt;&#34; + &#34;&lt;th&gt;Feeding&lt;/th&gt;&#34; + &#34;&lt;th&gt;Other Cost&lt;/th&gt;&#34; + &#34;&lt;th&gt;Total&lt;/th&gt;&#34; + &#34; &lt;/tr&gt; &lt;/tfoot&gt;&#34;; } #endregion string strOpenTBody = &#34;&lt;tbody&gt;&#34;; string strCloseTBody = &#34;&lt;/tbody&gt;&#34;; string strTR = &#34;&#34;; string strFinalOutput = &#34;&#34;; datafunctions dfs = new datafunctions(); DataTable dtSearch = new DataTable(); dtSearch = dfs._dataTable_NoParameter(selectstatement); //if (dfs.sqlUserError.Trim() != &#34;&#34;) return dfs.sqlUserError; if (dtSearch.Rows.Count &gt; 0) { #region if col == 8 { // re-arrange the rows for (int i = 0; i &lt; dtSearch.Rows.Count; i++) { strTR = strTR + &#34;&lt;tr &gt;&#34; + &#34;&lt;td&gt; &#34; + &#34; &lt;span&gt;&#34; + (i + 1).ToString() + &#34;&lt;/span&gt; &#34; + &#34;&lt;/td&gt;&#34; + &#34;&lt;td&gt; &lt;span class=&#39;lblStaffID&#39; id=&#39;lblStaffID&#34; + (i + 1).ToString() + &#34;&#39;&gt;&#34; + dtSearch.Rows[i][0].ToString().Trim() + &#34;&lt;/span&gt;&lt;/td&gt;&#34; + &#34;&lt;td&gt; &lt;span class=&#39;lblsurname&#39; id=&#39;lblsurname&#34; + (i + 1).ToString() + &#34;&#39;&gt;&#34; + dtSearch.Rows[i][1].ToString().Trim() + &#34;&lt;/span&gt;&lt;/td&gt;&#34; + &#34;&lt;td&gt; &lt;span class=&#39;lblothernames&#39; id=&#39;lblothernames&#34; + (i + 1).ToString() + &#34;&#39;&gt;&#34; + dtSearch.Rows[i][2].ToString().Trim() + &#34;&lt;/span&gt;&lt;/td&gt;&#34; + &#34;&lt;td&gt; &#34; + &#34; &lt;input name=&#39;txtcoursefee&#39; onkeypress=&#39;return validateFloatKeyPress(this, event)&#39; value=&#34; + dtSearch.Rows[i][3].ToString().Trim() + &#34; type=&#39;text&#39; id=&#39;txtcoursefee&#34; + (i + 1).ToString().Trim() + &#34;&#39; class=&#39;txtcoursefee&#39; style=&#39;width:100px;&#39; /&gt; &#34; + &#34;&lt;/td&gt;&#34; + &#34;&lt;td&gt; &#34; + &#34; &lt;input name=&#39;txtaccomod&#39; onkeypress=&#39;return validateFloatKeyPress(this, event)&#39; value=&#34; + dtSearch.Rows[i][4].ToString().Trim() + &#34; type=&#39;text&#39; id=&#39;txtaccomod&#34; + (i + 1).ToString().Trim() + &#34;&#39; class=&#39;txtaccomod&#39; style=&#39;width:100px;&#39; /&gt; &#34; + &#34;&lt;/td&gt;&#34; + &#34;&lt;td&gt; &#34; + &#34; &lt;input name=&#39;txttranspot&#39; onkeypress=&#39;return validateFloatKeyPress(this, event)&#39; value=&#34; + dtSearch.Rows[i][5].ToString().Trim() + &#34; type=&#39;text&#39; id=&#39;txttranspot&#34; + (i + 1).ToString().Trim() + &#34;&#39; class=&#39;txttranspot&#39; style=&#39;width:100px;&#39; /&gt; &#34; + &#34;&lt;/td&gt;&#34; + &#34;&lt;td&gt; &#34; + &#34; &lt;input name=&#39;txtfeeding&#39; onkeypress=&#39;return validateFloatKeyPress(this, event)&#39; value=&#34; + dtSearch.Rows[i][6].ToString().Trim() + &#34; type=&#39;text&#39; id=&#39;txtfeeding&#34; + (i + 1).ToString().Trim() + &#34;&#39; class=&#39;txtfeeding&#39; style=&#39;width:100px;&#39; /&gt; &#34; + &#34;&lt;/td&gt;&#34; + &#34;&lt;td&gt; &#34; + &#34; &lt;input name=&#39;txtothercst&#39; onkeypress=&#39;return validateFloatKeyPress(this, event)&#39; value=&#34; + dtSearch.Rows[i][7].ToString().Trim() + &#34; type=&#39;text&#39; id=&#39;txtothercst&#34; + (i + 1).ToString().Trim() + &#34;&#39; class=&#39;txtothercst&#39; style=&#39;width:100px;&#39; /&gt; &#34; + &#34;&lt;/td&gt;&#34; + &#34;&lt;td&gt; &#34; + &#34; &lt;input name=&#39;txttotcst&#39; onkeypress=&#39;return validateFloatKeyPress(this, event)&#39; value=&#34; + dtSearch.Rows[i][8].ToString().Trim() + &#34; type=&#39;text&#39; id=&#39;txttotcst&#34; + (i + 1).ToString().Trim() + &#34;&#39; class=&#39;price_sum&#39; style=&#39;width:100px;&#39; disabled /&gt; &#34; + &#34;&lt;/td&gt;&#34; + &#34;&lt;/tr&gt;&#34;; } } #endregion strFinalOutput = strOpenTableTag + strtHeader + strOpenTBody + strTR.Trim() + strCloseTBody + strCloseTableTag; } else { //strFinalOutput = dfs.sqlUserError; strFinalOutput = &#34;&lt;div class=&#39;alert alert-info&#39;&gt;No List!.&lt;/div&gt;&#34;; } dtSearch.Dispose(); if (strFinalOutput.Trim() != &#34;&#34;) { if (strFinalOutput.ToUpper().Trim().Contains(&#34;NO LIST!.&#34;)) { // lblerror.Text = &#34;There is no staff.&#34;; } tablecontainer.InnerHtml = strFinalOutput; } } </pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/448511/Calculate-Row-total-while-Searching-in-jQuery-DataTable-plugin/https://www.aspforums.net:443/Threads/448511/Calculate-Row-total-while-Searching-in-jQuery-DataTable-plugin/Wed, 19 Dec 2018 02:04:02 GMTCalculate Row total while Searching in jQuery DataTable plugin<p>Yes i am using datatable plugin</p>https://www.aspforums.net:443/Threads/448511/Calculate-Row-total-while-Searching-in-jQuery-DataTable-plugin/https://www.aspforums.net:443/Threads/448511/Calculate-Row-total-while-Searching-in-jQuery-DataTable-plugin/Wed, 19 Dec 2018 02:07:24 GMTCalculate Row total while Searching in jQuery DataTable plugin<p>Hi&nbsp;RumeValid,</p> <p>Refer below sample code.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;&gt; &lt;head runat=&#34;server&#34;&gt; &lt;title&gt;&lt;/title&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;link rel=&#34;stylesheet&#34; type=&#34;text/css&#34; href=&#34;//cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css&#34; /&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;//cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; $(function () { var table = $(&#39;[id*=sample_2]&#39;).DataTable(); CalculateRowTotal(); $(&#39;input[type=search]&#39;).keyup(function () { table.column(1).search($(this).val()).draw(); }); $(&#39;input[type=text]&#39;).on(&#39;keyup&#39;, function () { CalculateRowTotal(); }); function CalculateRowTotal() { $(&#39;#sample_2&#39;).find(&#39;tr:has(td)&#39;).each(function () { var trs = $(this); var tds = trs.find(&#39;td&#39;); var cou = $(tds).find(&#39;[id*=txtcoursefee]&#39;).val() != &#34;&#34; ? $(tds).find(&#39;[id*=txtcoursefee]&#39;).val() : &#34;0&#34;; var acco = $(tds).find(&#39;[id*=txtaccomod]&#39;).val() != &#34;&#34; ? $(tds).find(&#39;[id*=txtaccomod]&#39;).val() : &#34;0&#34;; var trans = $(tds).find(&#39;[id*=txttranspot]&#39;).val() != &#34;&#34; ? $(tds).find(&#39;[id*=txttranspot]&#39;).val() : &#34;0&#34;; var feeding = $(tds).find(&#39;[id*=txtfeeding]&#39;).val() != &#34;&#34; ? $(tds).find(&#39;[id*=txtfeeding]&#39;).val() : &#34;0&#34;; var ot = $(tds).find(&#39;[id*=txtothercst]&#39;).val() != &#34;&#34; ? $(tds).find(&#39;[id*=txtothercst]&#39;).val() : &#34;0&#34;; $(tds).find(&#39;[id*=txttotcst]&#39;).val(parseInt(cou) + parseInt(acco) + parseInt(trans) + parseInt(feeding) + parseInt(ot)); }); } }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id=&#34;form1&#34; runat=&#34;server&#34;&gt; &lt;div id=&#34;tablecontainer&#34; runat=&#34;server&#34;&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p><strong><span style="text-decoration: underline;">Namespaces</span></strong></p> <pre class="brush: csharp">using System.Data;</pre> <p><strong><span style="text-decoration: underline;">Code</span></strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string strtHeader = &#34;&#34;; string strCloseTableTag = &#34;&lt;/table&gt;&#34;; string strOpenTableTag = &#34;&lt;table class=&#39;hover compact order-column cell-border&#39; cellspacing=&#39;0&#39; width=&#39;100%&#39; id=&#39;sample_2&#39;&gt;&#34;; strtHeader = &#34;&lt;thead&gt;&lt;tr&gt;&#34; + &#34;&lt;th&gt;S/No&lt;/th&gt;&#34; + &#34;&lt;th&gt;Staff ID&lt;/th&gt;&#34; + &#34;&lt;th&gt;Surname&lt;/th&gt;&#34; + &#34;&lt;th&gt;Othernames&lt;/th&gt;&#34; + &#34;&lt;th&gt;Course Fee&lt;/th&gt;&#34; + &#34;&lt;th&gt;Accomodation&lt;/th&gt;&#34; + &#34;&lt;th&gt;Transport&lt;/th&gt;&#34; + &#34;&lt;th&gt;Feeding&lt;/th&gt;&#34; + &#34;&lt;th&gt;Other Cost&lt;/th&gt;&#34; + &#34;&lt;th&gt;Total&lt;/th&gt;&#34; + &#34;&lt;/tr&gt;&lt;/thead&gt;&#34; + &#34;&lt;tfoot&gt;&lt;tr&gt;&#34; + &#34;&lt;th&gt;S/No&lt;/th&gt;&#34; + &#34;&lt;th&gt;Staff ID&lt;/th&gt;&#34; + &#34;&lt;th&gt;Surname&lt;/th&gt;&#34; + &#34;&lt;th&gt;Othernames&lt;/th&gt;&#34; + &#34;&lt;th&gt;Course Fee&lt;/th&gt;&#34; + &#34;&lt;th&gt;Accomodation&lt;/th&gt;&#34; + &#34;&lt;th&gt;Transport&lt;/th&gt;&#34; + &#34;&lt;th&gt;Feeding&lt;/th&gt;&#34; + &#34;&lt;th&gt;Other Cost&lt;/th&gt;&#34; + &#34;&lt;th&gt;Total&lt;/th&gt;&#34; + &#34; &lt;/tr&gt; &lt;/tfoot&gt;&#34;; string strOpenTBody = &#34;&lt;tbody&gt;&#34;; string strCloseTBody = &#34;&lt;/tbody&gt;&#34;; string strTR = &#34;&#34;; string strFinalOutput = &#34;&#34;; DataTable dtSearch = new DataTable(); dtSearch.Columns.AddRange(new DataColumn[] { new DataColumn(&#34;Sno&#34;, typeof(int)),new DataColumn(&#34;StaffId&#34;, typeof(string)),new DataColumn(&#34;Surname&#34;,typeof(string)), new DataColumn(&#34;Othernames&#34;,typeof(string)), new DataColumn(&#34;CourseFee&#34;,typeof(int)), new DataColumn(&#34;Accomodation&#34;,typeof(int)), new DataColumn(&#34;Transport&#34;,typeof(int)),new DataColumn(&#34;Feeding&#34;,typeof(int)),new DataColumn(&#34;Othercost&#34;,typeof(int))}); dtSearch.Rows.Add(711, &#34;Staff 1&#34;, &#34;Name 1&#34;, 12, 23, 45, 36, 75); dtSearch.Rows.Add(800, &#34;Staff 2&#34;, &#34;Name 2&#34;, 0, 0, 0, 0, 0); if (dtSearch.Rows.Count &gt; 0) { for (int i = 0; i &lt; dtSearch.Rows.Count; i++) { strTR = strTR + &#34;&lt;tr &gt;&#34; + &#34;&lt;td&gt; &#34; + &#34; &lt;span&gt;&#34; + (i + 1).ToString() + &#34;&lt;/span&gt; &#34; + &#34;&lt;/td&gt;&#34; + &#34;&lt;td&gt; &lt;span class=&#39;lblStaffID&#39; id=&#39;lblStaffID&#34; + (i + 1).ToString() + &#34;&#39;&gt;&#34; + dtSearch.Rows[i][0].ToString().Trim() + &#34;&lt;/span&gt;&lt;/td&gt;&#34; + &#34;&lt;td&gt; &lt;span class=&#39;lblsurname&#39; id=&#39;lblsurname&#34; + (i + 1).ToString() + &#34;&#39;&gt;&#34; + dtSearch.Rows[i][1].ToString().Trim() + &#34;&lt;/span&gt;&lt;/td&gt;&#34; + &#34;&lt;td&gt; &lt;span class=&#39;lblothernames&#39; id=&#39;lblothernames&#34; + (i + 1).ToString() + &#34;&#39;&gt;&#34; + dtSearch.Rows[i][2].ToString().Trim() + &#34;&lt;/span&gt;&lt;/td&gt;&#34; + &#34;&lt;td&gt; &#34; + &#34; &lt;input name=&#39;txtcoursefee&#39; value=&#34; + dtSearch.Rows[i][3].ToString().Trim() + &#34; type=&#39;text&#39; id=&#39;txtcoursefee&#34; + (i + 1).ToString().Trim() + &#34;&#39; class=&#39;txtcoursefee&#39; style=&#39;width:100px;&#39; /&gt; &#34; + &#34;&lt;/td&gt;&#34; + &#34;&lt;td&gt; &#34; + &#34; &lt;input name=&#39;txtaccomod&#39; value=&#34; + dtSearch.Rows[i][4].ToString().Trim() + &#34; type=&#39;text&#39; id=&#39;txtaccomod&#34; + (i + 1).ToString().Trim() + &#34;&#39; class=&#39;txtaccomod&#39; style=&#39;width:100px;&#39; /&gt; &#34; + &#34;&lt;/td&gt;&#34; + &#34;&lt;td&gt; &#34; + &#34; &lt;input name=&#39;txttranspot&#39; value=&#34; + dtSearch.Rows[i][5].ToString().Trim() + &#34; type=&#39;text&#39; id=&#39;txttranspot&#34; + (i + 1).ToString().Trim() + &#34;&#39; class=&#39;txttranspot&#39; style=&#39;width:100px;&#39; /&gt; &#34; + &#34;&lt;/td&gt;&#34; + &#34;&lt;td&gt; &#34; + &#34; &lt;input name=&#39;txtfeeding&#39; value=&#34; + dtSearch.Rows[i][6].ToString().Trim() + &#34; type=&#39;text&#39; id=&#39;txtfeeding&#34; + (i + 1).ToString().Trim() + &#34;&#39; class=&#39;txtfeeding&#39; style=&#39;width:100px;&#39; /&gt; &#34; + &#34;&lt;/td&gt;&#34; + &#34;&lt;td&gt; &#34; + &#34; &lt;input name=&#39;txtothercst&#39; value=&#34; + dtSearch.Rows[i][7].ToString().Trim() + &#34; type=&#39;text&#39; id=&#39;txtothercst&#34; + (i + 1).ToString().Trim() + &#34;&#39; class=&#39;txtothercst&#39; style=&#39;width:100px;&#39; /&gt; &#34; + &#34;&lt;/td&gt;&#34; + &#34;&lt;td&gt; &#34; + &#34; &lt;input name=&#39;txttotcst&#39; value=&#34; + dtSearch.Rows[i][8].ToString().Trim() + &#34; type=&#39;text&#39; id=&#39;txttotcst&#34; + (i + 1).ToString().Trim() + &#34;&#39; class=&#39;price_sum&#39; style=&#39;width:100px;&#39; disabled /&gt; &#34; + &#34;&lt;/td&gt;&#34; + &#34;&lt;/tr&gt;&#34;; } strFinalOutput = strOpenTableTag + strtHeader + strOpenTBody + strTR.Trim() + strCloseTBody + strCloseTableTag; } else { strFinalOutput = &#34;&lt;div class=&#39;alert alert-info&#39;&gt;No List!.&lt;/div&gt;&#34;; } dtSearch.Dispose(); if (strFinalOutput.Trim() != &#34;&#34;) { if (strFinalOutput.ToUpper().Trim().Contains(&#34;NO LIST!.&#34;)) { } tablecontainer.InnerHtml = strFinalOutput; } } }</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><strong><span style="text-decoration: underline;"><img src="https://i.imgur.com/41geUJ2.gif" alt="" width="472" height="112" /></span></strong></p>https://www.aspforums.net:443/Threads/448511/Calculate-Row-total-while-Searching-in-jQuery-DataTable-plugin/https://www.aspforums.net:443/Threads/448511/Calculate-Row-total-while-Searching-in-jQuery-DataTable-plugin/Wed, 19 Dec 2018 05:59:13 GMT