/django-jqgrid

django utilities allowing easy handling and configuration of jqGrids

Primary LanguagePythonBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

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
    	fields = ['id', 'name', 'desc'] # optional 
    	url = reverse_lazy('grid_handler')
    	caption = 'My First Grid' # optional
    	colmodel_overrides = {
       		'id': { 'editable': False, 'width':10 },
   	 	}
  1. 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")
  1. Define urls for those views.
	url(r'^examplegrid/$', grid_handler, name='grid_handler'),
	url(r'^examplegrid/cfg/$', grid_config, name='grid_config'),
  1. 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 
        	);
    	});
	});