asp.net mvc - Hide buttons on the page by special attribute Jquery -


i'm new in web. have such table:

<tbody>         @foreach (var item in model)         {             <tr>                 <td>                     @item.datestart.toshortdatestring()                 </td>                 <td>                     @item.dateend.toshortdatestring()                 </td>                 <td data-name="@item.id" data-approved="@item.approved.tostring()">                     @item.approved.tostring()                 </td>                                 <td>                     @item.firstname.tostring() @item.lastname.tostring()                 </td>                 <td>                     @item.position.tostring()                 </td>                  <td>                     <button class="btn btn-primary accept-button" data-id="@item.id">accept</button>                                    <button class="btn btn-danger decline-button" data-id="@item.id"> decline</button>                 </td>             </tr>         }     </tbody> 

and wrote script buttons on page:

$(document).ready(function () {     $('#requesttable').datatable(         {             aocolumns: [             { mdataprop: "datestart", stitle: "date start" },             { mdataprop: "dateend", stitle: "date end" },             { mdataprop: "approved", stitle: "approved" },             { mdataprop: "data", stitle: "employee" },             { mdataprop: "position", stitle: "position" },             { mdataprop: "", stitle: "" }             ],             columndefs: [{                 targets: 'no-sort',                 orderable: false             }]         });      $('button.accept-button').click(function () {         var id = $(this).attr('data-id')         var appr = $('td[data-name="' + id + '"]');         appr[0].textcontent = "true";         $.ajax({             type: "post",             url: "/tablerequest/acceptrequest",             data: { 'id': id },             success: function (msg) {             }         });     });     var tempid;     $('button.decline-button').click(function () {         tempid = $(this).attr('data-id')         var appr = $('td[data-name="' + tempid + '"]');         appr[0].textcontent = "false";         $("#dialog").dialog()     });     $('button.ok-request').click(function () {         var message = $('textarea#commentfordecline').val();          $.ajax({             type: "post",             url: "/tablerequest/declinerequest",             data: { 'message': message, 'id': tempid },             success: function (msg) {             }         });         $("#dialog").dialog('close');         $('textarea#commentfordecline').val('');     });      hidebuttons();  });  function hidebuttons(){         // var appr = $('td[data-name="' + id + '"]');        var appr = $("td[data-approved='false']");        var         if(appr[0].textcontent == "true")        {            $('button.accept-button').hide();        }        if(appr[0].textcontent == "false")        {            $('button.decline-button').hide();        }     }; 

i wanna hide buttons in depends on approved field in table. if @item.approved.tostring() true - need hide butto "accept", else - "decline". can me?

<td> @if (item.approved) {                   <button class="btn btn-danger decline-button" data-id="@item.id"> decline</button> } else {     <button class="btn btn-primary accept-button" data-id="@item.id">accept</button>  } </td> 

i assumed item.approved boolean. if not have alter if-clause.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -