html - How to swap particular row among list of row based on value scanned in text box in jquery -



html - How to swap particular row among list of row based on value scanned in text box in jquery -

i'm developing web application in i'm generating table row dynamically based on value entered in text box. 1 condition, if come in same value twise (one after another), should not add together row. if come in 10 different values , @ 10th time if come in value entered row should come top in table. (it should not add together again).

for illustration entering value 1,2,3,4,5,6,7,8,9,10 , 11th time entering value 1 in table 1 row should come @ top (1,10,9,8,7,6,5,4,3,2).

if entered 1,1 should add together row 1 time. please help me finish this. in advance.

$(document).ready(function(){ var wholestring=""; /*to search shipment id through webservice: begin */ $('#searchkey').change(function(){ allboxes=new array(); allboxes[0]=0; $.ajax({ type : 'post', url : '@routes.application.searchkey()', info : { searchkey : $(this).val(), orgname: 'fb' }, success : function(data) { console.log("success"+data); var arr = data.split('&'); if((arr[0]!="null")&&(arr[1]!="null")&&(!wholestring.contains(arr[0]))) { wholestring=wholestring+"::"+arr[0]; var table='<tr class="active" style="height:40px;">'; table += '<td><input type="checkbox" class="radio" name="name1" value="1" checked /></td>'; table += '<td> <button type="button" class="btn btn-primary btn-sm dark_button width-150px">'+arr[0]+'</button></td>'; table += '<td>'+arr[1]+'</td>'; table+='<td><i style="color:green;font-size:18px" class="fa fa-check"></i></td>'; table += '</tr>'; // append table in box_content $("#boxnumberarea").append(table); // creates tbody , append lastly inserted table var $tbody = $('<tbody>').appendto('#boxnumberarea table:last'); allboxes[0]=arr[0]; } }, error : function() { console.log("failed"); } }); $(this).val(''); /*to search shipment id through webservice: end */ }); if (!('contains' in string.prototype)) string.prototype.contains = function (str, startindex) { homecoming -1 !== string.prototype.indexof.call(this, str, startindex); }; }); </script>

assume within tbody ajax portion been appending.now code not allow duplicate value. along want above feature well.

to so, while adding rows compare info , if found prepend row else new row.

i've setup sample here. check out.

updated sample match construction : http://jsfiddle.net/wv5jlmqd/1/ .

code snippet checking existing similar row :

$("#tab tr td:first-child").each(function (idx) { if ($(this).text() === num) { foundat = idx; homecoming false; } });

adding rows :

if (foundat !== -1) { $row = $("#tab tr").eq(foundat); } else { $row = $("<tr><td>" + num + "</td><td> sample text</td>"); }

refer :

.each()

.prepend()

.eq()

jquery html textbox html-table

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

java - Parsing XML, skip certain tags -

c# - ASP.NET MVC Sequence contains no matching element -