28 February, 2008

Xml elements and attributes in the ExtJS table

Ext JS - JavaScript Library is pretty powerful JavaScript/AJAX framework for building of Rich Internet Applications.

I've used it in my last public web project: Ubuntu index.

ExtJS has set of useful UI controls, internal components and strong AJAX, XML and JSON support.

E.g. you can present this XML file:


<?xml version="1.0"?>


<item id="alien-arena">
<name>Alien Arena</name>

<item id="nexuiz">

<item id="openarena">


as a table via this HTML + JavaScript code:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<title>ExtJS Table Sample</title>
<link rel="stylesheet" type="text/css" href="ext/resources/css/ext-all.css"/>
<script type="text/javascript" src="ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext/ext-all.js"></script>

<script type="text/javascript">
Ext.onReady(function() {
var reader = new Ext.data.XmlReader({record: "item"},
[{name: "id", mapping:"@id"}, "name"]);

var store = new Ext.data.Store({url: "items.xml", reader: reader});

var columnModel = new Ext.grid.ColumnModel([
{header: "Id", dataIndex: "id"},
{header: "Name", dataIndex: "name"}]);

var table = new Ext.grid.GridPanel({
store: store,
height: 200,
cm: columnModel,
renderTo: "table"

<div id="table" style="width:300px; height:200px;"></div>

Here is the browser's view:

1 comment:

Anonymous said...

It gives an error as
Access Denied...