Columns

class djqgrid.columns.Column(title, model_path, **kwargs)

A Column object represents one Grid column

The Column object defines how a column’s value is retrieved and how it is formatted.

Column is effectively an abstract class - Grids should be using its derived classes.

Initializes a column.

Args:

title: The column’s title in the grid. title.lower() is the default column name. model_path: The column’s data field’s path in the model.

For example, if this is the Name column in a grid of Person models, and the person’s name is in the fullname attribute of the Person model, model_path should be fullname. model_path can also access attributes in nested objects: innerobj.attr will be resolved to model_instance.innerobj.attr

**kwargs: All other arguments are copied as is to the column’s colModel.

get_sort_name()

Returns the column’s “sort-name”, which is used to apply ordering on a queryset.

The default implementation is to take the model_path and replace each . with __ .

model

Returns the colModel

render_html(model)

Returns an HTML representation of the column’s value.

The default implementation is to return the text value.

render_text(model)

Returns a text representation of the column’s value.

The default implementation is to convert get_model_value to a unicode string.

title

Returns the name that goes in the colName JSON

class djqgrid.columns.TextColumn(title, model_path, **kwargs)

A column that contains simple text strings.

This is basically just a Column. We create a new class because it seems more tidy.

Initializes a column.

Args:

title: The column’s title in the grid. title.lower() is the default column name. model_path: The column’s data field’s path in the model.

For example, if this is the Name column in a grid of Person models, and the person’s name is in the fullname attribute of the Person model, model_path should be fullname. model_path can also access attributes in nested objects: innerobj.attr will be resolved to model_instance.innerobj.attr

**kwargs: All other arguments are copied as is to the column’s colModel.

class djqgrid.columns.TemplateColumn(title, model_path, template=None, template_name=None, **kwargs)

A column that is rendered by a Django template

Use a TemplateColumn when you want the column to contain complex HTML content.

Due to a bug in jqGrid, cell values cannot contain HTML - it conflicts with inline editing. So instead, the cell values returned by the default Grid.get_json_data method will be the text rendering of the column. The HTML data will be placed in the html property of the row’s data.

To actually display the HTML data we use a formatter, called customHtmlFormatter, which resides in djqgrid_utils.js

Initializes a TemplateColumn

Args:
title: The column’s title model_path: The column’s model path template: A Django template that will be rendered template_name: A name of a Django template that will be rendered. **kwargs: Additional arguments that will be passed directly to the column’s colModel

You can specify a template or a template_name, but not both.

class djqgrid.columns.LinkColumn(title, model_path, url_builder, **kwargs)

A column that is rendered as a single <a href=...> link

Initializes a LinkColumn.

Args:
title: The column’s title model_path: The column’s model_path url_builder: a function that takes a model and returns the link’s URL **kwargs: Additional arguments passed directly to the column’s colModel