PDA

View Full Version : Grid from markup: th within tbody and specifying data type



poptart
4 Jun 2007, 4:40 AM
Hi all,

I'm trying to adapt the from markup grid example (http://extjs.com/deploy/ext/examples/grid/from-markup.html) to work with my existing tables. My tables are a little more complex than in the example. Here is one of my tables where the first cell of each row of the tbody is a th:


<table id="the-table" rules="groups" summary="This table summarises recent orders">
<thead>
<tr style="background:#eeeeee;">
<th>Date/Time</th>
<th>Reference</th>
<th>Order Number</th>
<th>Product Code</th>
<th>Description</th>
<th>Status</th>
</tr>
</thead>

<tbody>
<tr class="odd">
<th>18/05/2007</th>
<td><a href="orders/order_detail.asp?id=1">Web Order</a></td>
<td>ON</td>
<td>001</td>
<td>GAS OIL</td>
<td>New</td>
</tr>
<tr class="even">
<th>18/02/2005</th>
<td><a href="orders/order_detail.asp?id=2">101373</a></td>
<td>2</td>
<td>001</td>
<td>GAS OIL</td>
<td>Entered</td>
</tr>
<tr class="odd">
<th>03/01/2005</th>
<td><a href="orders/order_detail.asp?id=3">101295</a></td>
<td>2</td>
<td>001</td>
<td>GAS OIL</td>
<td>Analysed</td>
</tr>
<tbody>
</table>Currently the th cell contents are not included when I create a grid from the above markup - only the td cell contents are used.

I've tracked this down to line 50 in from-markup.js:


mapping: 'td:nth('+(i+1)+')/@innerHTML'The code is only looking to include td elements and not th elements. I therefore tried updating the xpath expression to include td or th elements as follows:


mapping: 'td|th:nth('+(i+1)+')/@innerHTML'which gave me the following error in firebug:


[Exception... "'Error parsing selector, parsing failed at "|th:nth(1)/@innerHTML"' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "<unknown>" data: no]I also tried the following to select all elements as follows:


mapping: '*:nth('+(i+1)+')/@innerHTML'This included the content of both the th and td elements but it also matched my links (a elements) within the td and added an extra column for these.

Can anyone suggest any alternative xpath that might work to select only td and th elements?

The second problem is that when sorting the columns the grid does not recognise that the data in my first column is of the type date. Is there a way to specify the data type when creating a grid from markup?

Many thanks in advance for any pointers or advice :)