Guest User

Untitled

a guest
Jul 22nd, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.95 KB | None | 0 0
  1. <div id="mygrid">
  2. </div>
  3. <div>
  4. @{
  5. var grid = new WebGrid(Model.DataDiriList, rowsPerPage: 15, canPage: true, canSort: true, ajaxUpdateContainerId: "gridContent");
  6. @grid.GetHtml(
  7. tableStyle: "row",
  8. alternatingRowStyle: "alt",
  9. columns: grid.Columns(
  10. grid.Column("ID", format: @<text> <span class="display-mode">@item.ID </span> <label id="UserID" class="edit-mode">@item.ID</label> </text>, style: "col1Width" ),
  11. grid.Column("Nama", "Nama", format: @<text> <span class="display-mode"> <label id="lblNama" >@item.Nama</label> </span> <input type="text" id="Nama" value="@item.Nama" class="edit-mode" /></text>, style: "col2Width"),
  12. grid.Column("Umur", "Umur", format: @<text> <span class="display-mode"> <label id="lblUmur" >@item.Umur</label> </span> <input type="text" id="Umur" value="@item.Umur" class="edit-mode" /></text>, style: "col2Width"),
  13. grid.Column(header: "Active", format:@<text> <span class="display-mode"> <label id="lblActive">@item.ActiveStatus</label> </span> <input id="chkActive" type="checkbox" @((item.Active == true) ? " checked=checked" : "") name="CloseSelling" value="@item.Active" class="edit-mode" onchange="adchange()" /></text>, style: "col2Width"),
  14. grid.Column("Action", format: @<text>
  15. <button class="edit-user display-mode" >Edit</button>
  16. <button class="save-user edit-mode" >Save</button>
  17. <button class="cancel-user edit-mode" >Cancel</button>
  18. </text>, style: "col3Width" , canSort: false)
  19. ));
  20. }
  21. </div>
  22.  
  23. @section scripts
  24. {
  25. <script type="text/javascript">
  26.  
  27. $(document).ready(function () {
  28. $('.edit-mode').hide();
  29. $('.edit-user, .cancel-user').on('click', function () {
  30. var tr = $(this).parents('tr:first');
  31. tr.find('.edit-mode, .display-mode').toggle();
  32. });
  33. $(function () {
  34. $('#chkActive').click(function () {
  35. alert($(this).val() + ' ' + (this.checked ? 'checked' : 'unchecked'));
  36. });
  37. });
  38.  
  39. $(".save-user").on("click", function () {
  40. var tr = $(this).parent().parent();
  41. var t = tr.find("#Nama").val();
  42. var Umur = tr.find('#Umur').val();
  43. var chkActive = $('#chk').attr('checked') ? "True" : "False";
  44. var ID = tr.find('#UserID').html();
  45. alert(chkActive);
  46.  
  47. $.ajax({
  48. url: '@Url.Action("UpdateUser", "Home")',
  49. type: "Post",
  50. data: { CustomerNameId: t, UserID: ID, Umur: Umur,Active: chkActive},
  51. dataType: 'json',
  52. success: function (result) {
  53. $("#mygrid").html('');
  54. $("#mygrid").html(result);
  55. }
  56. });
  57.  
  58. tr.find("#lblNama").text(t);
  59. tr.find("#lblUmur").text(Umur);
  60. tr.find('.edit-mode, .display-mode').toggle();
  61. });
  62.  
  63. });
  64. </script>
  65. }
  66.  
  67. public JsonResult UpdateUser(string CustomerNameId, string UserID, string Umur, bool Active)
  68. {
  69. var ID = Convert.ToInt32(UserID);
  70. var IntUmur = Convert.ToInt32(Umur);
  71. var dd = db.DataDiris.AsQueryable().Where(r => r.ID == ID).Single();
  72. dd.ID = ID;
  73. dd.Nama = CustomerNameId;
  74. dd.Umur = IntUmur;
  75. dd.Active = Active;
  76.  
  77. db.Entry(dd).State = EntityState.Modified;
  78. db.SaveChanges();
  79. string message = "Success";
  80. return Json(message, JsonRequestBehavior.AllowGet);
  81. }
  82.  
  83. var IsDisabled = tr.find("#IsDisabled").val();
  84.  
  85. tr.find("#lblIsDisabled").text(IsDisabled);
  86.  
  87. "IsDisabled": IsDisabled,
  88.  
  89. grid.Column("IsDisabled", "IsDisabled", format: @<text> <span class="display-mode"> <label id="lblIsDisabled">@item.IsDisabled</label> </span>
  90. <input class="edit-mode" id="IsDisabled" name="IsDisabled" type="checkbox" value="@if (item.IsDisabled){<text>True</text>}else{<text>False</text>}" @if(item.IsDisabled){<text>checked</text>}/>
  91. </text>),
  92.  
  93. @Html.CheckBox("ShowOnChart", (bool)item.ShowOnChart, new { @class = "edit-mode", value = item.ShowOnChart })
  94.  
  95. <script type="text/javascript">
  96. $(function () {
  97. $('input:checkbox').change(function () {
  98. if ($(this).attr("checked")) {
  99. $(this).attr("value", true);
  100. } else {
  101. $(this).attr("value", false);
  102. }
  103. });
  104. });
  105. $(document).ready(function () {
  106. $('input[type=checkbox]').each(function () {
  107. if ($(this).attr("checked")) {
  108. $(this).attr("value", true);
  109. } else {
  110. $(this).attr("value", false);
  111. }
  112. });
  113. });
  114. </script>
  115.  
  116. $('.edit-mode:checkbox').change(...
  117.  
  118. bool? isDisabled
Add Comment
Please, Sign In to add comment