Building a Web Grid - Part 5
I wanted to have a “pluggable” editor system for the grid so programmers could customize the widgets that appear in the cell when editing begins. This post discusses how to create a custom editor and use it in grijq.
The structure of an editor
An editor for grijq has the following form:
1 | var myEditor = { |
You then pass it as an option to the grijq
widget when you create it:
1 | $('#some-table').grijq({editors: {'mytype': myEditor}}); |
And make sure that you’ve marked the column header with the key of your custom editor:
1 | <table id="some-table" width="100"> |
Or pass in the type to the cols parameter of the grijq
widget:
1 | $('#some-table').grijq({ |
A custom editor that displays a <select>
I don’t have much use for <select>s. However, you may like them. Let’s make a custom editor that creates a <select> that contains shirt sizes.
1 | var shirtSizeEditor = { |
Now, we’ll create a table that uses that.
1 | <table id="some-table" width="300"> |
Then, we create the grid with grijq.
1 | $('#some-table').grijq({ |
And you get this handsome devil. It’s a working grid, right there. Click on a cell. Type ‘l’ or ‘m’ or ‘s’. Press ‘F2’. (And, the fact that it doesn’t keep its changed value is by design. The grid isn’t broken. Check out the example simple knockout integration to see how to persist values.)
Shirt Size |
---|
Large |
Medium |
Small |
WTF?!?!? |