def jqgrid_javascript(options={})
      s = ''

      if table_to_grid
        s << %Q^
        tableToGrid("##{dom_id}", #{to_json});
        ^
        s << %Q^
        grid_#{dom_id} = jQuery("##{dom_id}")
        ^
      else
        s << %Q^
        grid_#{dom_id} = jQuery("##{dom_id}").jqGrid(#{to_json})
        ^
      end

      s << ';'

      # tag the grid as fluid so we can find it on resize events  
      if width_fit == :fluid
        s << %Q^
        jQuery("##{dom_id}").addClass("fluid");
        ^
      end

      # override tableToGrid colmodel options as needed (sortable)
      #s << %Q^ .jqGrid('setColProp','Title',{sortable: false})^

      # resize method
      if resizable
        s << %Q^
        jQuery("##{dom_id}").jqGrid('gridResize', #{resizable.to_json});
        ^
      end

      # pager buttons (navGrid)
      if pager
        nav_params = {
            'edit' => edit_button.present?,
            'add' => add_button.present?,
            'del' => delete_button.present?,
            'search' => search_button.present? || search_multiple.present?,
            'view' => view_button.present?,
            'refresh' => refresh_button.present?
        }.merge(jqgrid_nav_options||{})

        s << %Q^
        jQuery("##{dom_id}").jqGrid('navGrid', '##{pager}',
               #{nav_params.to_json},
               #{edit_button_options.to_json_with_js},
               #{add_button_options.to_json_with_js},
               #{delete_button_options.to_json_with_js},
               #{search_button_options.to_json_with_js},
               #{view_button_options.to_json_with_js}
               );
        ^
      end

      if arranger_type.include?(:hide_show)
        s << %Q^
        jQuery("##{dom_id}").jqGrid('navButtonAdd','##{pager}',{ 
               caption: "Columns", 
               title: "Hide/Show Columns", 
               onClickButton : function (){ jQuery("##{dom_id}").jqGrid('setColumns',
                 #{arranger_options(:hide_show).to_json_with_js} );
               }
        });
        ^
      end
      if arranger_type.include?(:chooser)
        # hackey way to build the string but gets it done
        chooser_code = %Q^ function (){ jQuery('##{dom_id}').jqGrid('columnChooser', {
                          done : function (perm) {
                            if (perm)  {
                              this.jqGrid('remapColumns', perm, true);
                              var gwdth = this.jqGrid('getGridParam','width');
                              this.jqGrid('setGridWidth',gwdth);
                            }
                          } })}^
        chooser_opts = {
            'caption' => 'Columns',
            'title' => 'Arrange Columns',
            'onClickButton' => 'chooser_code'
        }.merge(arranger_options(:chooser))
        s << %Q^
        jQuery("##{dom_id}").jqGrid('navButtonAdd','##{pager}', #{chooser_opts.to_json.gsub('"chooser_code"', chooser_code)} );
        ^
      end

      if search_toolbar
        # I wish we could put this in the header rather than the pager
        s << %Q^
        jQuery("##{dom_id}").jqGrid('navButtonAdd',"##{pager}", { caption:"Toggle", title:"Toggle Search Toolbar", buttonicon: 'ui-icon-pin-s', onClickButton: function(){ grid_#{dom_id}[0].toggleToolbar() } });
        jQuery("##{dom_id}").jqGrid('navButtonAdd',"##{pager}", { caption:"Clear", title:"Clear Search", buttonicon: 'ui-icon-refresh', onClickButton: function(){ grid_#{dom_id}[0].clearToolbar() } });
        jQuery("##{dom_id}").jqGrid('filterToolbar');
        ^
      end

      if sortable_rows
        # I wish we could put this in the header rather than the pager
        s << %Q^
        jQuery("##{dom_id}").jqGrid('sortableRows');
        ^
      end

      # TODO: built in event handlers, eg
      # loadError 
      # onSelectRow, onDblClickRow, onRightClickRow etc

      #unless search_toolbar == :visible
      #  s << %Q^
      #  grid_#{dom_id}[0].toggleToolbar();
      #  ^
      #end

      # # keep page controls centered (jqgrid bug) [eg appears when :width_fit => :scroll]
      # s << %Q^ $("##{pager}_left").css("width", "auto"); ^

      s
    end
def jqgrid_javascript(options={})
      s = ''

      if table_to_grid
        s << %Q^
        tableToGrid("##{dom_id}", #{to_json});
        ^
        s << %Q^
        grid_#{dom_id} = jQuery("##{dom_id}")
        ^
      else
        s << %Q^
        grid_#{dom_id} = jQuery("##{dom_id}").jqGrid(#{to_json})
        ^
      end

      s << ';'

      # tag the grid as fluid so we can find it on resize events  
      if width_fit == :fluid
        s << %Q^
        jQuery("##{dom_id}").addClass("fluid");
        ^
      end

      # override tableToGrid colmodel options as needed (sortable)
      #s << %Q^ .jqGrid('setColProp','Title',{sortable: false})^

      # resize method
      if resizable
        s << %Q^
        jQuery("##{dom_id}").jqGrid('gridResize', #{resizable.to_json});
        ^
      end

      # pager buttons (navGrid)
      if pager
        nav_params = {
            'edit' => edit_button.present?,
            'add' => add_button.present?,
            'del' => delete_button.present?,
            'search' => search_button.present? || search_multiple.present?,
            'view' => view_button.present?,
            'refresh' => refresh_button.present?
        }.merge(jqgrid_nav_options||{})

        s << %Q^
        jQuery("##{dom_id}").jqGrid('navGrid', '##{pager}',
               #{nav_params.to_json},
               #{edit_button_options.to_json_with_js},
               #{add_button_options.to_json_with_js},
               #{delete_button_options.to_json_with_js},
               #{search_button_options.to_json_with_js},
               #{view_button_options.to_json_with_js}
               );
        ^
      end

      if arranger_type.include?(:hide_show)
        s << %Q^
        jQuery("##{dom_id}").jqGrid('navButtonAdd','##{pager}',{ 
               caption: "Columns", 
               title: "Hide/Show Columns", 
               onClickButton : function (){ jQuery("##{dom_id}").jqGrid('setColumns',
                 #{arranger_options(:hide_show).to_json_with_js} );
               }
        });
        ^
      end
      if arranger_type.include?(:chooser)
        # hackey way to build the string but gets it done
        chooser_code = %Q^ function (){ jQuery('##{dom_id}').jqGrid('columnChooser', {
                          done : function (perm) {
                            if (perm)  {
                              this.jqGrid('remapColumns', perm, true);
                              var gwdth = this.jqGrid('getGridParam','width');
                              this.jqGrid('setGridWidth',gwdth);
                            }
                          } })}^
        chooser_opts = {
            'caption' => 'Columns',
            'title' => 'Arrange Columns',
            'onClickButton' => 'chooser_code'
        }.merge(arranger_options(:chooser))
        s << %Q^
        jQuery("##{dom_id}").jqGrid('navButtonAdd','##{pager}', #{chooser_opts.to_json.gsub('"chooser_code"', chooser_code)} );
        ^
      end

      if search_toolbar
        # I wish we could put this in the header rather than the pager
        s << %Q^
        jQuery("##{dom_id}").jqGrid('navButtonAdd',"##{pager}", { caption:"Toggle", title:"Toggle Search Toolbar", buttonicon: 'ui-icon-pin-s', onClickButton: function(){ grid_#{dom_id}[0].toggleToolbar() } });
        jQuery("##{dom_id}").jqGrid('navButtonAdd',"##{pager}", { caption:"Clear", title:"Clear Search", buttonicon: 'ui-icon-refresh', onClickButton: function(){ grid_#{dom_id}[0].clearToolbar() } });
        jQuery("##{dom_id}").jqGrid('filterToolbar');
        ^
      end

      if sortable_rows
        # I wish we could put this in the header rather than the pager
        s << %Q^
        jQuery("##{dom_id}").jqGrid('sortableRows');
        ^
      end

      # TODO: built in event handlers, eg
      # loadError 
      # onSelectRow, onDblClickRow, onRightClickRow etc

      #unless search_toolbar == :visible
      #  s << %Q^
      #  grid_#{dom_id}[0].toggleToolbar();
      #  ^
      #end

      # # keep page controls centered (jqgrid bug) [eg appears when :width_fit => :scroll]
      # s << %Q^ $("##{pager}_left").css("width", "auto"); ^

      s
    end
-----------------