UI Integrations

Sortable Columns

This method is integrated in jqGrid, so there it is not necessary to do something special. The method allow to reorder the grid columns using the mouse. The only necessary setting in this case is to set the sortable option in jqGrid to true.
using our example this will look like this:

Function which will be called when the user press Ok button. In the current implementation we cal remapColumns method in order to reorder the columns

msel

mixed

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”)

multiselect

dlog

mixed

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”)

dialog

dlog_opts

mixed

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

cleanup

function

Function to cleanup the dialog, and select. Also calls the done function with no permutation (to indicate that the columnChooser was aborted

Function done defined above has the following definition in the original jqGrid code:

In order to do other things after reordering you can redefine this option. For example let say that we want to recalculate the width of some elements on the page after the user show or hide some columns. The code can look like this:

jQuery("#list").jqGrid('columnChooser',{
done :function(perm){if(perm){// "OK" button are clickedthis.jqGrid("remapColumns", perm,true);// the grid width is probably changed co we can get new width// and adjust the width of other elements on the page//var gwdth = this.jqGrid("getGridParam","width");//this.jqGrid("setGridWidth",gwdth);}else{// we can do some action in case of "Cancel" button clicked}}});

Used jQuery UI widget(s) and other plugins

jQuery UI core

jQuery UI sortable widget.

jQuery UI dialog

jQuery multiselect plugin

The jQuery multiselect plugin can be obained from here. Also this plugin is included in the plugins directory of the jqGrid build

Sortable Rows

This method allows reordering (sorting) grid rows in a visual manner using a mouse.
Calling convetions:

jQuery("#list").sortableRows(options);

or using the new API

jQuery("#list").jqGrid('sortableRows', options);

where options is a object with properties listed below.
The method is fully compatible with jQuery UI sortable widget. This means that we can set any option and event available in this widget. For more information on the options and events look here

Used jQuery UI widget(s) and other plugins

jQuery UI core

jQuery UI sortable widget.

Known problems

Currently this method does not work correct in FireFox versions 3.0.x, Chrome and Safari browsers due to little problem in sortable widget, which we hope they will be corrected in future release of jQuery UI.

Method does not work currently when treeGrid is enabled - i.e. you can not use the method to reorder tree rows.

Resizable Grid

This method allow to re size the grid width and/or height in visual manner using a mouse.

Calling convetions:

jQuery("#list").gridResize(options);

or using the new API

jQuery("#list").jqGrid('gridResize', options);

where options is a object with properties listed above.
The method is fully compatible with jQuery UI resizable widget. This means that we can set any option and event available in this widget. For more information on the options and events look here

Used jQuery UI widget(s) and other plugins

jQuery UI core

jQuery UI resizable widget.

Known problems

Using the grid hide button (the button in the caption) does not hide the content created from the resizable widget. This cause appearing of borders of the grid after it is hidden.

Drag and Drop rows between grids

This method allow drag and drop rows between two or more grids using a mouse.

Calling convetions:

jQuery("#list").gridDnD(options);

or using the new API

jQuery("#list").jqGrid('gridDnD', options);

where options is a object with properties listed below.

Options

Name

Type

Description

Default

connectWith

string

Determines the target grid(s) to which the row should be dropped. The option is a string. In case of more than one grid the ids should be delemited with comma - i.e “#grid1, #grid2”

empty string

onstart

function

This event raises when we start drag a row from the source grid (i.e. to which this method is applied). Parameters passed to this event are the event handler and a prepared ui object. For more information refer to jQuery UI draggable events

null

onstop

function

This event is triggered when dragging stops. Parameters passed to this even are the event handler and a prepared ui object. For more information refer to jQuery UI draggable events

null

beforedrop

function

This event raises before droping the row to the grid specified in connectWith option. Parameters passed to this event are the event handler, prepared ui object, data which will be inserted into the grid in name value pair, source grid object and target(this) grid object.
If the event return object in value name pair this object will be inserted into the target grid.

null

ondrop

function

This event raises after the droping the row to the grid specified in connectWith option. Parameters passed to this event are the event handler, prepared ui object, data which is inserted into the grid in name value pair. For more information refer to jQuery UI droppable events

null

drop_opts

object

Predefined options which can be applied to the droppable grid (specified with connectWith option above). Also you can set any option and event (except drop event which is replaced with ondrop event listed above). For more information refer to jQuery UI droppable

{ activeClass : “ui-state-active”,
hoverClass : “ui-state-hover”
}

drag_opts

object

Predefined options which can be applied to the draggable grid (i.e. to which this method is applied). Also you can set any option and event (except start and stop events which are replaced with onstart and onstop events listed above). For more information refer to jQuery UI draggable

If set to true this means that only fields that have equal names will be added to the target grid. Note that we use addRowData to insert new row, which means that if some field with name “a” on source grid is hidden they can appear on the target grid. The default value of false mean that the grid data will be added to the target counted from the first column from source.

false

droppos

string

Determines where to add the new row. Can be first which mean as first row of the grid and last - as last row in the target grid.

first

autoid

boolean

This option determines how the new row id should be generated. If this option is true we generate a id wich begin with string setted with the option autoidprefix (see below) and a random number. If this option is false the id can be either the the next record count or value determined by key property in colModel.
If the parameter is defined as function this function should return value which will act as id to the target grid. Parameters passed in this case is the data array which will be inserted into the target grid row

true

autoidprefix

string

This option have sense only if the option autoid is set to true and determines the prefix of the new genearted id.

dnd_

dragcopy

boolean

Copies the source row to the target rather than moving it. (GridDnD only).

false

Used jQuery UI widget(s) and other plugins

jQuery UI core

jQuery UI draggable widget.

jQuery UI droppable widget.

Known problems

The method does not work well in Safari and Chrome because of the bug in the draggable widget. The effect is that the entry text is selected bellow the draggable row

Example

In the example below we will create three grids with id grid1, grid2 and grid3. We will make so that rows from grid1 can be dragged to grid2 and grid3 and rows from grid2 can be dragged only to grid1.

Essentially, the ui object isn't a UI object for the rows. Which means it isn't “fully compatible” with the jQuery UI widget as one would expect. It appears it binds to the table, not the rows. You'll have to getRowData and detect sorting yourself. Which shouldn't be too bad; you're sorting by some column, just read that one.

Personally, I'm storing ordering on the “start” sortable event, and checking on “update”, because I want to allow sorting even when filtering / searching / non-manually-sorted, and there's no 100% reliable way to get the current dragged row that I can find. That way, I just compare row IDs, and pass only the changes (I sort by inserting A above B, and by no other means, so this is easy). Of course, this has its own problems. Such as if the user sorts by descending, they may keep trying to put 1 above 2; succeeding, but never keeping that order visually while the grid is sorted in reverse.