javascript - In a table each row has an edit button. Show or hide the button depends on another value in this row -


i have table defined in js file, last column edit button each row, let user edit row's information. there's row, third row, mlscode. when value of mlscode "a" or "b", should show edit button in row. below part of table builder:

var agentsearchresultbuilder =  [     { colname: "first name", dataname: "firstname" },     { colname: "last name", dataname: "lastname" },     { colname: "mls", dataname: "mlscode" },      {         colname: "mls office status",         dataname: "office.mlsisactive",         template: '{{if office.mlsisactive}}active{{else}}inactive{{/if}}',         styleclass: '{{if office.mlsisactive}}active{{else}}inactive{{/if}}'     },     {         colname: "edit",         template: "<button title='edit agent information' class='tinybutton editagent' id='${mlscode}'>edit</button>"     } ]; 

i wrote following code control edit button visibility, first matching row can show button. later matching rows didn't show button. don't know what's wrong.

$("button.editagent", table).button().hide(); //to hide buttons  $('#agentsearchtable >tbody >tr').each(function () {             var value = $(this).find('td:eq(2)').text();             if (value === "a") {                 $("#a").show();                 alert(value);                  /*i use test if reaches every                     matching row or not. turns out yes. each matching row                      gives alert. edit button didn't show(only first                      matching 1 shows.)                   */             }             if (value === "b") {                 $("#b").show();                 alert(value);             }         }); 

also, noticed in agentsearchresultbuilder, there's code {if}..{/if}, wonder there way can in template of edit button. if id equals 'a' or 'b', display button. totally new c#, javascript , jquery. first project. hope me, lot!

this:

$("#a").show(); 

isn't going work, because depends on having same id on buttons in multiple rows, isn't legal html. browser ignoring id attributes ids it's seen. want use class, rather id (add button-${mlscode} end of class attribute , remove id attribute), , use this:

$(this).find('.button-a').show(); 

to show it.


Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

html - Outlook 2010 Anchor (url/address/link) -