PDA

View Full Version : dynamic extjs (like php)



len
17 Mar 2009, 2:31 AM
<html>
<head>
<title>Editor Grids</title>
<link rel="stylesheet" type="text/css" href="../../../lib/extjs/resources/css/ext-all.css" />
<script type="text/javascript" src="../../../lib/extjs/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../../../lib/extjs/ext-all.js"></script>
<script>
//ommitted codes here
.
.
.
//ommitted codes here
grid = new Ext.grid.EditorGridPanel({
renderTo: document.body,
frame:true,
title: 'Movie Database',
height:300,
width:520,
enableColumnMove: false,
store: store,
clicksToEdit: 2,
columns: [
{header: 'Movie Title', dataIndex: 'title', editor: title_edit},
{header: 'Director', dataIndex: 'director', editor: director_edit},
{header: 'Released', dataIndex: 'released', renderer: Ext.util.Format.dateRenderer('Y-m-d'), editor: release_edit},
{header: 'Genre', dataIndex: 'genre', renderer: genre_name, editor: genre_edit},
{header: 'Tagline', dataIndex: 'tagline', editor: tagline_edit}
],
//ommitted codes here
.
.
.
//ommitted codes here
</script>
</head>
<body>
</body>
</html>

hello guys,

i have a php file (containing the code above).
in the code, i have a grid basically, as can be seen above, i hard coded the parts of the columns config object (header, dataIndex, etc...).
i have a table in the database containing 5 columns (the ones being displayed in the grid) so everything seems to be fine (as the store queries the table).

my problem is if i modify the number of columns in the table, i have to modify again (hard-coding again) the above file since it's javascript(?)

in php i could have done this dynamically i mean i could have used the for each () statement (instead of hard coding every column) to display every column queried from the table.

is there a way in extjs to do the same thing, not requiring rehard-coding the code every time a change is made in the structure of the backend tables (or by the result set being returned by the query)? or is this a limitation we have to live with using extjs?

please enlighten me

thanks a lot guys

mjlecomte
17 Mar 2009, 4:23 AM
Read top of
http://extjs.com/deploy/dev/docs/?class=Ext.data.JsonReader

Then search for autoGrid, metaGrid, etc. For example here's one:
http://extjs.com/forum/showthread.php?p=275575#post275575

17 Mar 2009, 4:47 AM
There is no reason why you can't have PHP that generates JavaScript dynamically. Hell, it's been done for many years now.