PageRenderTime 63ms CodeModel.GetById 36ms RepoModel.GetById 0ms app.codeStats 0ms

/University_3/Views/Professor/Index2.cshtml

https://gitlab.com/ahmad-hamzavi/grid_test1
Razor | 140 lines | 124 code | 16 blank | 0 comment | 3 complexity | f37e601a2397d3e59a0fbeeb7f838455 MD5 | raw file
  1. <div class="row">
  2. <button id="btnGet">استادان</button>
  3. <button id="btnBulkAdd">اضافه کردن</button>
  4. </div>
  5. <div class="row">
  6. <div class="col-xs-12">
  7. <table id="grid-data" class="table table-condensed table-hover table-striped">
  8. <thead>
  9. <tr>
  10. <th data-column-id="id" data-order="desc" data-type="numeric" data-identifier="true">ردیف</th>
  11. <th data-column-id="FirstName" data-order="desc">نام</th>
  12. <th data-column-id="LastName" data-order="desc">نام خانوادگی</th>
  13. <th data-column-id="Choices" data-formatter="Choices" data-sortable="false">انتخاب</th>
  14. </tr>
  15. </thead>
  16. </table>
  17. </div>
  18. </div>
  19. @section MyScripts
  20. {
  21. <script>
  22. $(function () {
  23. var ajaxload = function () {
  24. var grid = $("#grid-data").bootgrid({
  25. ajax: true,
  26. ajaxSettings: {
  27. method: "POST",
  28. cache: true
  29. },
  30. selection: true,
  31. multiSelect: true,
  32. rowSelect: true,
  33. keepSelection: true,
  34. url: "/Professor/AllProfessors",
  35. multiSort: true,
  36. formatters:
  37. {
  38. "Choices": function (column, row) {
  39. var s = "<div class='d' id=" + row.id +"><select name='r' class='we'>"
  40. //for (var i= 0; i < row.Choices.length; i++) {
  41. // s += ("<option>" + row.Choices[i] + "</option>");
  42. //}
  43. s += ("</select><button class='details'>Details</button>"+
  44. "</div>");
  45. $(".we").visibility = 'hidden';
  46. return s;
  47. }
  48. }
  49. }).on("selected.rs.jquery.bootgrid", function (e, rows) {
  50. }).on("deselected.rs.jquery.bootgrid", function (e, rows) {
  51. //var rowIds = [];
  52. //for (var i = 0; i < rows.length; i++) {
  53. // rowIds.push(rows[i].id);
  54. //}
  55. //alert("Deselect: " + rowIds.join(","));
  56. }).on("loaded.rs.jquery.bootgrid", function (e,rows) {
  57. /* Executes after data is loaded and rendered */
  58. $(".image").hide();
  59. var we = $(".we");
  60. var details = $(".details");
  61. we.click(function (e) {
  62. var $this = $(this);
  63. //$this.parent().children('.image').show();
  64. $.ajax({
  65. url: "/Professor/Choices/"+ $(this).parent().attr("id"), success: function (result) {
  66. setChoices(result, $this);
  67. },
  68. type:"POST"
  69. });
  70. });
  71. details.click(function () {
  72. details.parent().children(".image").slideUp();
  73. $(this).parent().children('.image').slideDown();
  74. details.show();
  75. $(this).hide();
  76. });
  77. //$('a').live('click', function () {
  78. // var $this = $(this),
  79. // $parentTR = $this.closest('tr');
  80. // $parentTR.clone().insertAfter($parentTR);
  81. //});
  82. // var res = "";
  83. details.bind('click', function () {
  84. $("[id*=details]").remove();
  85. var $this = $(this);
  86. $.ajax({
  87. url: "/Professor/Details/" + $(this).parent().attr("id"), success: function (result) {
  88. setDetails(result, $this);
  89. //console.log($(this));
  90. },
  91. type: "POST"
  92. });
  93. // $('<tr id=details' + $(this).parent().attr("id") + '><td colspan="5">gfhfghgfh</td></tr>').insertAfter($(this).closest('tr'));
  94. });
  95. });
  96. }
  97. var setDetails = function (result,_this) {
  98. console.log(_this.parent().attr("id"));
  99. $('<tr id=details' + _this.parent().attr("id") + '><td colspan="5">'+result+'</td></tr>').insertAfter(_this.closest('tr'));
  100. };
  101. var setChoices = function (result, _this) {
  102. var s = "";
  103. for (var i = 0; i < result.length; i++) {
  104. s += ("<option>" + result[i] + "</option>");
  105. }
  106. $(".we").children().remove();
  107. _this.append(s);
  108. };
  109. $("#btnGet").click(function () {
  110. ajaxload();
  111. });
  112. $("#btnBulkAdd").click(function () {
  113. $.ajax({
  114. url: "/Professor/AddBulkProfessor", success: function (result) {
  115. if (result == "OK") {
  116. ajaxload();
  117. };
  118. }
  119. });
  120. });
  121. ajaxload();
  122. });
  123. </script>
  124. }