javascript - Working with variables outside of jquery UI dialog -


i have .each loops through table rows , compares information entered user attempting add. have conditionals in loop duplicate entries across each of s in row. depending on how many match, there's yes/no decision user make. if user chooses yes, current row needs removed. using jquery ui , having problems getting dialog box know row remove, or having .each loop know selected in dialog. .each loop looks this:

$('#tblselectedlist > tbody > tr').each(function() { 

here's code dialog (within in loop):

                $('<div></div>').appendto('body')                 .html('<div><h6>delete duplicate?</h6></div>')                 .dialog({                     modal: true,                     title: 'delete message',                     zindex: 10000,                     autoopen: true,                     width: 'auto',                     resizable: false,                     buttons: {                         yes: function () {                             removethis = 1;                             blnadd = 1;                             $(this).dialog("close");                         },                         no: function () {                             blnadd = 0;                             $(this).dialog("close");                         }                     },                     close: function (event, ui) {                         $(this).remove();                     }                 }); 

and method using remove rows:

var id = $(this).attr('id').substring(7,$(this).attr('id').length); $('#tblselectedlist #row-'+id).remove(); 

everything works independently, can't dialog , containing .each loop know other doing.

i think first thing need set id each row in table. way can know how find row later on. can done using jquery if not possible when creating actual table.

here example:

var rowscount = 0; $('#tblselectedlist > tbody > tr').each(function() {    //setting row ids like: tblselectedlist_row0,tblselectedlist_row1,...,tblselectedlist_rown    $(this).attr("id","tblselectedlist_row" + (rowscount++)); } 

so in foreach loop actuall row dupplicate detaction logic this:

$('#tblselectedlist > tbody > tr').each(function() {        //determine here row should deleted        var rowshouldbedeleted = true;      if ( rowshouldbedeleted ){         //here invoke our promt delete function passing row identifier         //which explained below         promptfordelete(this.id);     } } 

then suggest using 2 functions:

  1. one ask question "promtfordelete".
  2. another 1 deletes row.

so first 1 need pass information required identify row should deleted "the row id", in case user selects "yes", along other data want display in prompt.

here example:

function promptfordelete(rowid){     $('<div></div>').appendto('body')             .html('<div><h6>delete duplicate?</h6></div>')             .dialog({                 modal: true,                 title: 'delete message',                 zindex: 10000,                 autoopen: true,                 width: 'auto',                 resizable: false,                 buttons: {                     yes: function () {                         deleterow(rowid);                         blnadd = 1;                         $(this).dialog("close");                     },                     no: function () {                         blnadd = 0;                         $(this).dialog("close");                     }                 },                 close: function (event, ui) {                     $(this).remove();                 }             }); } 

now second function "deleterow" have find row matches id , remove it.

here example:

function deleterow(rowid){      $(rowid).remove(); } 

and that's it.... hope makes sense you.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -