grid.setcolumns.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. ;(function($){
  2. /**
  3. * jqGrid extension for manipulating columns properties
  4. * Piotr Roznicki roznicki@o2.pl
  5. * http://www.roznicki.prv.pl
  6. * Dual licensed under the MIT and GPL licenses:
  7. * http://www.opensource.org/licenses/mit-license.php
  8. * http://www.gnu.org/licenses/gpl-2.0.html
  9. **/
  10. $.jgrid.extend({
  11. setColumns : function(p) {
  12. p = $.extend({
  13. top : 0,
  14. left: 0,
  15. width: 200,
  16. height: 'auto',
  17. dataheight: 'auto',
  18. modal: false,
  19. drag: true,
  20. beforeShowForm: null,
  21. afterShowForm: null,
  22. afterSubmitForm: null,
  23. closeOnEscape : true,
  24. ShrinkToFit : false,
  25. jqModal : false,
  26. saveicon: [true,"left","ui-icon-disk"],
  27. closeicon: [true,"left","ui-icon-close"],
  28. onClose : null,
  29. colnameview : true,
  30. closeAfterSubmit : true,
  31. updateAfterCheck : false,
  32. recreateForm : false
  33. }, $.jgrid.col, p ||{});
  34. return this.each(function(){
  35. var $t = this;
  36. if (!$t.grid ) { return; }
  37. var onBeforeShow = typeof p.beforeShowForm === 'function' ? true: false;
  38. var onAfterShow = typeof p.afterShowForm === 'function' ? true: false;
  39. var onAfterSubmit = typeof p.afterSubmitForm === 'function' ? true: false;
  40. var gID = $t.p.id,
  41. dtbl = "ColTbl_"+gID,
  42. IDs = {themodal:'colmod'+gID,modalhead:'colhd'+gID,modalcontent:'colcnt'+gID, scrollelm: dtbl};
  43. if(p.recreateForm===true && $("#"+IDs.themodal).html() != null) {
  44. $("#"+IDs.themodal).remove();
  45. }
  46. if ( $("#"+IDs.themodal).html() != null ) {
  47. if(onBeforeShow) { p.beforeShowForm($("#"+dtbl)); }
  48. $.jgrid.viewModal("#"+IDs.themodal,{gbox:"#gbox_"+gID,jqm:p.jqModal, jqM:false, modal:p.modal});
  49. if(onAfterShow) { p.afterShowForm($("#"+dtbl)); }
  50. } else {
  51. var dh = isNaN(p.dataheight) ? p.dataheight : p.dataheight+"px";
  52. var formdata = "<div id='"+dtbl+"' class='formdata' style='width:100%;overflow:auto;position:relative;height:"+dh+";'>";
  53. formdata += "<table class='ColTable' cellspacing='1' cellpading='2' border='0'><tbody>";
  54. for(i=0;i<this.p.colNames.length;i++){
  55. if(!$t.p.colModel[i].hidedlg) { // added from T. Tomov
  56. formdata += "<tr><td style='white-space: pre;'><input type='checkbox' style='margin-right:5px;' id='col_" + this.p.colModel[i].name + "' class='cbox' value='T' " +
  57. ((this.p.colModel[i].hidden===false)?"checked":"") + "/>" + "<label for='col_" + this.p.colModel[i].name + "'>" + this.p.colNames[i] + ((p.colnameview) ? " (" + this.p.colModel[i].name + ")" : "" )+ "</label></td></tr>";
  58. }
  59. }
  60. formdata += "</tbody></table></div>"
  61. var bS = !p.updateAfterCheck ? "<a href='javascript:void(0)' id='dData' class='fm-button ui-state-default ui-corner-all'>"+p.bSubmit+"</a>" : "",
  62. bC ="<a href='javascript:void(0)' id='eData' class='fm-button ui-state-default ui-corner-all'>"+p.bCancel+"</a>";
  63. formdata += "<table border='0' class='EditTable' id='"+dtbl+"_2'><tbody><tr style='display:block;height:3px;'><td></td></tr><tr><td class='DataTD ui-widget-content'></td></tr><tr><td class='ColButton EditButton'>"+bS+"&#160;"+bC+"</td></tr></tbody></table>";
  64. p.gbox = "#gbox_"+gID;
  65. $.jgrid.createModal(IDs,formdata,p,"#gview_"+$t.p.id,$("#gview_"+$t.p.id)[0]);
  66. if(p.saveicon[0]==true) {
  67. $("#dData","#"+dtbl+"_2").addClass(p.saveicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  68. .append("<span class='ui-icon "+p.saveicon[2]+"'></span>");
  69. }
  70. if(p.closeicon[0]==true) {
  71. $("#eData","#"+dtbl+"_2").addClass(p.closeicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  72. .append("<span class='ui-icon "+p.closeicon[2]+"'></span>");
  73. }
  74. if(!p.updateAfterCheck) {
  75. $("#dData","#"+dtbl+"_2").click(function(e){
  76. for(i=0;i<$t.p.colModel.length;i++){
  77. if(!$t.p.colModel[i].hidedlg) { // added from T. Tomov
  78. var nm = $t.p.colModel[i].name.replace(/\./g, "\\.");
  79. if($("#col_" + nm,"#"+dtbl).attr("checked")) {
  80. $($t).jqGrid("showCol",$t.p.colModel[i].name);
  81. $("#col_" + nm,"#"+dtbl).attr("defaultChecked",true); // Added from T. Tomov IE BUG
  82. } else {
  83. $($t).jqGrid("hideCol",$t.p.colModel[i].name);
  84. $("#col_" + nm,"#"+dtbl).attr("defaultChecked",""); // Added from T. Tomov IE BUG
  85. }
  86. }
  87. }
  88. if(p.ShrinkToFit===true) {
  89. $($t).jqGrid("setGridWidth",$t.grid.width-0.001,true);
  90. }
  91. if(p.closeAfterSubmit) $.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal, onClose: p.onClose});
  92. if (onAfterSubmit) { p.afterSubmitForm($("#"+dtbl)); }
  93. return false;
  94. });
  95. } else {
  96. $(":input","#"+dtbl).click(function(e){
  97. var cn = this.id.substr(4);
  98. if(cn){
  99. if(this.checked) {
  100. $($t).jqGrid("showCol",cn);
  101. } else {
  102. $($t).jqGrid("hideCol",cn);
  103. }
  104. if(p.ShrinkToFit===true) {
  105. $($t).jqGrid("setGridWidth",$t.grid.width-0.001,true);
  106. }
  107. }
  108. return this;
  109. });
  110. }
  111. $("#eData", "#"+dtbl+"_2").click(function(e){
  112. $.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal, onClose: p.onClose});
  113. return false;
  114. });
  115. $("#dData, #eData","#"+dtbl+"_2").hover(
  116. function(){$(this).addClass('ui-state-hover');},
  117. function(){$(this).removeClass('ui-state-hover');}
  118. );
  119. if(onBeforeShow) { p.beforeShowForm($("#"+dtbl)); }
  120. $.jgrid.viewModal("#"+IDs.themodal,{gbox:"#gbox_"+gID,jqm:p.jqModal, jqM: true, modal:p.modal});
  121. if(onAfterShow) { p.afterShowForm($("#"+dtbl)); }
  122. }
  123. });
  124. }
  125. });
  126. })(jQuery);