Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
django utilities allowing easy handling and configuration of jqGrids
Python
Branch: master
Pull request Compare This branch is 10 commits ahead, 16 commits behind gerry:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.gitignore
AUTHORS
LICENSE
README.mkd
__init__.py
jqgrid.py
models.py
setup.py
tests.py
views.py

README.mkd

django-jqgrid

django-jqgrid aims to make integrating full support for jqgrid as simple as defining which models you want exposed, while still supporting the more advanced features.

After unexpected interest, I have decided to provide an early release in the form as a utility class. This release is not stable or intented for production use. I will be cleaning up, restructuring (to a more flexible classed generic handler), and adding documentation/examples soon. Until then, you have been warned!

Prerequisites

Example

  1. First define your grid somewhere (e.g., grids.py). Only a model or queryset and a url are required.

    class ExampleGrid(JqGrid):
        model = SomeFancyModel # could also be a queryset
        form  = SomeFancyModelForm
        fields = ['id', 'name', 'desc'] #optional 
        pager_id = "#pager" #optional
        url = reverse('grid_handler')
        edit_url = reverse('grid_edit') #optional.
        caption = 'My First Grid' # optional
        colmodel_overrides = {
            'id': { 'editable': False, 'width':10 },
        }
    
  2. Create views to handle requests.

    def grid_handler(request):
        # handles pagination, sorting and searching
        grid = ExampleGrid()
        return HttpResponse(grid.get_json(request), mimetype="application/json")
    
    def grid_config(request):
        # build a config suitable to pass to jqgrid constructor   
        grid = ExampleGrid()
        return HttpResponse(grid.get_config(), mimetype="application/json")
    
    def grid_edit(request):
        #use only if you want jqgrid editing (edit means add, edit and delete
        # operations) your stuff
        grid = ExampleGrid()
        return HttpResponse(grid.handle_edit(request))
    
  3. Define urls for those views.

    url(r'^examplegrid/$', grid_handler, name='grid_handler'),
    url(r'^examplegrid/cfg/$', grid_config, name='grid_config'),
    url(r'^examplegrid/edit/$', grid_edit, name='grid_edit'),
    
  4. Configure jgrid to use the defined urls.

    $(function () {
        $.getJSON("{% url grid_config %}", function(data){
            $("#mygrid")
                .jqGrid(data)
                .navGrid('#pager', 
                    {add: false, edit: false, del: false, view: true},
            {}, // edit options
            {}, // add options
            {}, // del options 
            { multipleSearch:true, closeOnEscape:true }, // search options 
            { jqModal:false, closeOnEscape:true} // view options 
            );
        });
    });
    

Validation

It was only possible to see data in earlier django-jqgrid versions; Editing operations (which means adding, editing and deleting operations to jqGrid) is a bit more complicated because of data validation. That's why you must pass a Form for the grid.

Something went wrong with that request. Please try again.