2012-03-13 19 views
5

इस example को देखकर, ध्यान दें कि खोज बटन पर क्लिक करने से इसके पीछे एक अंधेरे ओवरले के साथ एक मोडल फॉर्म आता है। अब ध्यान दें कि कॉलम Chooser बटन पर क्लिक करने से एक मोडल फॉर्म आता है लेकिन इसके पीछे कोई ओवरले नहीं है।jQGrid कॉलम Chooser मोडल ओवरले

मेरा सवाल है: मैं अपने कॉलम Chooser पॉपअप के पीछे दिखाई देने के लिए अंधेरे ओवरले कैसे प्राप्त करूं? इस तरह

$grid.jqGrid('navButtonAdd', '#pager', { 
      caption: "", 
      buttonicon: "ui-icon-calculator", 
      title: "Choose columns", 
      onClickButton: function() { 
.... 

: इस कोड को

jqModal : true, 

:

उत्तर

18

वर्तमान की option undocumented हैं columnChooser:

$(this).jqGrid('columnChooser', {modal: true}); 

The demo इसे प्रदर्शित करें। एक भी $.jgrid.col के लिए सम्मान के साथ columnChooser के लिए डिफ़ॉल्ट पैरामीटर सेट कर सकते हैं:

$.extend(true, $.jgrid.col, { 
    modal: true 
}); 

हाल ही में मैं the suggestion तैनात columnChooser का एक छोटा कार्यक्षमता बढ़ाने के लिए, लेकिन बदलाव का ही a part jqGrid की वर्तमान कोड है। फिर भी नए संस्करण में नए dialog_opts विकल्प के संबंध में अधिक jQuery UI Dialog विकल्प सेट करना संभव होगा। उदाहरण के लिए निम्नलिखित का उपयोग

$(this).jqGrid('columnChooser', { 
    dialog_opts: { 
     modal: true, 
     minWidth: 470, 
     show: 'blind', 
     hide: 'explode' 
    } 
}); 

पूर्ण सुविधाओं जो मैं सुझाव तुम सिर्फ columnChooser के मानक कार्यान्वयन अधिलेखित कर सकते हैं का उपयोग करने के लिए संभव हो जाएगा। निम्न में से एक कोड

$.jgrid.extend({ 
    columnChooser : function(opts) { 
     var self = this; 
     if($("#colchooser_"+$.jgrid.jqID(self[0].p.id)).length) { return; } 
     var selector = $('<div id="colchooser_'+self[0].p.id+'" style="position:relative;overflow:hidden"><div><select multiple="multiple"></select></div></div>'); 
     var select = $('select', selector); 

     function insert(perm,i,v) { 
      if(i>=0){ 
       var a = perm.slice(); 
       var b = a.splice(i,Math.max(perm.length-i,i)); 
       if(i>perm.length) { i = perm.length; } 
       a[i] = v; 
       return a.concat(b); 
      } 
     } 
     opts = $.extend({ 
      "width" : 420, 
      "height" : 240, 
      "classname" : null, 
      "done" : function(perm) { if (perm) { self.jqGrid("remapColumns", perm, true); } }, 
      /* msel is either the name of a ui widget class that 
       extends a multiselect, or a function that supports 
       creating a multiselect object (with no argument, 
       or when passed an object), and destroying it (when 
       passed the string "destroy"). */ 
      "msel" : "multiselect", 
      /* "msel_opts" : {}, */ 

      /* dlog is either the name of a ui widget class that 
       behaves in a dialog-like way, or a function, that 
       supports creating a dialog (when passed dlog_opts) 
       or destroying a dialog (when passed the string 
       "destroy") 
       */ 
      "dlog" : "dialog", 

      /* dlog_opts is either an option object to be passed 
       to "dlog", or (more likely) a function that creates 
       the options object. 
       The default produces a suitable options object for 
       ui.dialog */ 
      "dlog_opts" : function(opts) { 
       var buttons = {}; 
       buttons[opts.bSubmit] = function() { 
        opts.apply_perm(); 
        opts.cleanup(false); 
       }; 
       buttons[opts.bCancel] = function() { 
        opts.cleanup(true); 
       }; 
       return $.extend(true, { 
        "buttons": buttons, 
        "close": function() { 
         opts.cleanup(true); 
        }, 
        "modal" : opts.modal ? opts.modal : false, 
        "resizable": opts.resizable ? opts.resizable : true, 
        "width": opts.width+20, 
        resize: function (e, ui) { 
         var $container = $(this).find('>div>div.ui-multiselect'), 
          containerWidth = $container.width(), 
          containerHeight = $container.height(), 
          $selectedContainer = $container.find('>div.selected'), 
          $availableContainer = $container.find('>div.available'), 
          $selectedActions = $selectedContainer.find('>div.actions'), 
          $availableActions = $availableContainer.find('>div.actions'), 
          $selectedList = $selectedContainer.find('>ul.connected-list'), 
          $availableList = $availableContainer.find('>ul.connected-list'), 
          dividerLocation = opts.msel_opts.dividerLocation || $.ui.multiselect.defaults.dividerLocation; 

         $container.width(containerWidth); // to fix width like 398.96px      
         $availableContainer.width(Math.floor(containerWidth*(1-dividerLocation))); 
         $selectedContainer.width(containerWidth - $availableContainer.outerWidth() - ($.browser.webkit ? 1: 0)); 

         $availableContainer.height(containerHeight); 
         $selectedContainer.height(containerHeight); 
         $selectedList.height(Math.max(containerHeight-$selectedActions.outerHeight()-1,1)); 
         $availableList.height(Math.max(containerHeight-$availableActions.outerHeight()-1,1)); 
        } 
       }, opts.dialog_opts || {}); 
      }, 
      /* Function to get the permutation array, and pass it to the 
       "done" function */ 
      "apply_perm" : function() { 
       $('option',select).each(function(i) { 
        if (this.selected) { 
         self.jqGrid("showCol", colModel[this.value].name); 
        } else { 
         self.jqGrid("hideCol", colModel[this.value].name); 
        } 
       }); 

       var perm = []; 
       //fixedCols.slice(0); 
       $('option:selected',select).each(function() { perm.push(parseInt(this.value,10)); }); 
       $.each(perm, function() { delete colMap[colModel[parseInt(this,10)].name]; }); 
       $.each(colMap, function() { 
        var ti = parseInt(this,10); 
        perm = insert(perm,ti,ti); 
       }); 
       if (opts.done) { 
        opts.done.call(self, perm); 
       } 
      }, 
      /* Function to cleanup the dialog, and select. Also calls the 
       done function with no permutation (to indicate that the 
       columnChooser was aborted */ 
      "cleanup" : function(calldone) { 
       call(opts.dlog, selector, 'destroy'); 
       call(opts.msel, select, 'destroy'); 
       selector.remove(); 
       if (calldone && opts.done) { 
        opts.done.call(self); 
       } 
      }, 
      "msel_opts" : {} 
     }, $.jgrid.col, opts || {}); 
     if($.ui) { 
      if ($.ui.multiselect) { 
       if(opts.msel == "multiselect") { 
        if(!$.jgrid._multiselect) { 
         // should be in language file 
         alert("Multiselect plugin loaded after jqGrid. Please load the plugin before the jqGrid!"); 
         return; 
        } 
        opts.msel_opts = $.extend($.ui.multiselect.defaults,opts.msel_opts); 
       } 
      } 
     } 
     if (opts.caption) { 
      selector.attr("title", opts.caption); 
     } 
     if (opts.classname) { 
      selector.addClass(opts.classname); 
      select.addClass(opts.classname); 
     } 
     if (opts.width) { 
      $(">div",selector).css({"width": opts.width,"margin":"0 auto"}); 
      select.css("width", opts.width); 
     } 
     if (opts.height) { 
      $(">div",selector).css("height", opts.height); 
      select.css("height", opts.height - 10); 
     } 
     var colModel = self.jqGrid("getGridParam", "colModel"); 
     var colNames = self.jqGrid("getGridParam", "colNames"); 
     var colMap = {}, fixedCols = []; 

     select.empty(); 
     $.each(colModel, function(i) { 
      colMap[this.name] = i; 
      if (this.hidedlg) { 
       if (!this.hidden) { 
        fixedCols.push(i); 
       } 
       return; 
      } 

      select.append("<option value='"+i+"' "+ 
          (this.hidden?"":"selected='selected'")+">"+colNames[i]+"</option>"); 
     }); 
     function call(fn, obj) { 
      if (!fn) { return; } 
      if (typeof fn == 'string') { 
       if ($.fn[fn]) { 
        $.fn[fn].apply(obj, $.makeArray(arguments).slice(2)); 
       } 
      } else if ($.isFunction(fn)) { 
       fn.apply(obj, $.makeArray(arguments).slice(2)); 
      } 
     } 

     var dopts = $.isFunction(opts.dlog_opts) ? opts.dlog_opts.call(self, opts) : opts.dlog_opts; 
     call(opts.dlog, selector, dopts); 
     var mopts = $.isFunction(opts.msel_opts) ? opts.msel_opts.call(self, opts) : opts.msel_opts; 
     call(opts.msel, select, mopts); 
     // fix height of elements of the multiselect widget 
     var resizeSel = "#colchooser_"+$.jgrid.jqID(self[0].p.id), 
      $container = $(resizeSel + '>div>div.ui-multiselect'), 
      $selectedContainer = $(resizeSel + '>div>div.ui-multiselect>div.selected'), 
      $availableContainer = $(resizeSel + '>div>div.ui-multiselect>div.available'), 
      containerHeight, 
      $selectedActions = $selectedContainer.find('>div.actions'), 
      $availableActions = $availableContainer.find('>div.actions'), 
      $selectedList = $selectedContainer.find('>ul.connected-list'), 
      $availableList = $availableContainer.find('>ul.connected-list'); 
     $container.height($container.parent().height()); // increase the container height 
     containerHeight = $container.height(); 
     $selectedContainer.height(containerHeight); 
     $availableContainer.height(containerHeight); 
     $selectedList.height(Math.max(containerHeight-$selectedActions.outerHeight()-1,1)); 
     $availableList.height(Math.max(containerHeight-$availableActions.outerHeight()-1,1)); 
     // extend the list of components which will be also-resized 
     selector.data('dialog').uiDialog.resizable("option", "alsoResize", 
      resizeSel + ',' + resizeSel +'>div' + ',' + resizeSel + '>div>div.ui-multiselect'); 
    } 
}); 

मामले आप jquery.jqGrid.min.js के मूल को कम से कम संस्करण का उपयोग जारी रख सकते हैं और कोड जो उपयोग सिर्फ $(this).jqGrid('columnChooser'); हो सकता है शामिल करके ऐसा कर सकते हैं। सभी डिफ़ॉल्ट सेटिंग के साथ मिलकर ऐसा

$.extend(true, $.ui.multiselect, { 
    locale: { 
     addAll: 'Make all visible', 
     removeAll: 'Hidde All', 
     itemsCount: 'Avlialble Columns' 
    } 
}); 
$.extend(true, $.jgrid.col, { 
    width: 450, 
    modal: true, 
    msel_opts: {dividerLocation: 0.5}, 
    dialog_opts: { 
     minWidth: 470, 
     show: 'blind', 
     hide: 'explode' 
    } 
}); 
$grid.jqGrid('navButtonAdd', '#pager', { 
    caption: "", 
    buttonicon: "ui-icon-calculator", 
    title: "Choose columns", 
    onClickButton: function() { 
     $(this).jqGrid('columnChooser'); 
    } 
}); 

The demo दृष्टिकोण का प्रदर्शन किया जाएगा। परिवर्तन का मुख्य लाभ - वास्तव में आकार बदलने योग्य कॉलम चयनकर्ता:

enter image description here

UPDATED:Free jqGrid jqGrid, जो मैं 2014 के अंत के साथ शुरू विकसित की कांटा, कारण की columnChooser के संशोधित कोड में शामिल है।

+0

धन्यवाद ओलेग! – FastTrack

+0

@ फास्टट्रैक: आपका स्वागत है! – Oleg

+0

@ ओलेग स्थिर वस्तु है (मुझे लगता है कि यह स्थैतिक है) $ .jgrid.col कहीं भी दस्तावेज? मैं colchooser में अनुवाद जोड़ना चाहता हूं इसलिए प्रश्न – Harshit

1

सिर्फ कोड के माध्यम से तलाश कर दिया गया, इस लाइन जोड़ने की कोशिश

$grid.jqGrid('navButtonAdd', '#pager', { 
      caption: "", 
      buttonicon: "ui-icon-calculator", 
      title: "Choose columns", 
      jqModal : true, 
      onClickButton: function() { 
.... 
2

मुझे मोबाइल डिवाइस पर कोड का प्रयास करते समय निम्न त्रुटि मिलती है।

Result of expression 'selector.data('dialog').uiDialog' [undefined] is not an object. 

त्रुटि कोड की निम्न पंक्ति को इंगित करती है।

selector.data('dialog').uiDialog.resizable("option", "alsoResize", resizeSel + ',' + resizeSel +'>div' + ',' + resizeSel + '>div>div.ui-multiselect'); 

जब मैं कोड का निरीक्षण करता हूं, तो मुझे लगता है कि डेटा ऑब्जेक्ट में uiDialog नामक कुछ भी नहीं है।

+0

मुझे एक ही त्रुटि मिलती है। क्या आप jQuery 1.9+ का उपयोग कर रहे हैं? – Chris

+0

मेरे पास एक ही समस्या थी और कुछ और। प्रारंभ में यह स्क्रिप्ट अनुक्रमित हो गया (यानी मैंने कॉलम को एक अलग फ़ाइल में जोड़ा था - यह jqgrid स्क्रिप्ट शामिल होने के बाद होना चाहिए)। फिर इस त्रुटि से फंस गया - इसे ठीक नहीं कर सका लेकिन उन पंक्तियों पर टिप्पणी करने के बाद सबकुछ काम कर रहा है! अजीब –