PDA

View Full Version : run time Column and header based on xml response in grid for data.XmlReader



nikhilesh
13 Sep 2010, 11:37 PM
Hello ,

I want to create dynamic column rather than Add hardcode column in store in header this in store

[
{ name: 'Id'},
{ name: Name},
{ name: ServiceId}
]


i want to create coulmn and header based on my xml response


<?xml version="1.0" encoding="utf-8"?>
<Search xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:rrshuttle:lcl" xsi:schemaLocation="urn:rrshuttle:lcl Search.xsd">
<status>PROPER</status>
<MSG>Status msg goes here</MSG>
<ServiceDetails>
<Service>
<Id>0</Id>
<Name>Ride Share</Name>
<ServiceId>0</ServiceId>
</Service>
<Service>
<Id>1</Id>
<Name>Exclusive Van (7 Pass.)</Name>
<ServiceId>1</ServiceId>
</Service>
<Service>
<Id>11</Id>
<Name>Exclusive Van (9 Pass.)</Name>
<ServiceId>1</ServiceId>
</Service>
<Service>
<Id>12</Id>
<Name>Exclusive Van (14 Pass.)</Name>
<ServiceId>1</ServiceId>
</Service>
<Service>
<Id>2</Id>
<Name>Town Car</Name>
<ServiceId>2</ServiceId>
</Service>
<Service>
<Id>15</Id>
<Name>Express Service</Name>
<ServiceId>2</ServiceId>
</Service>
<Service>
<Id>3</Id>
<Name>Limousine</Name>
<ServiceId>3</ServiceId>
</Service>
<Service>
<Id>4</Id>
<Name>SUV</Name>
<ServiceId>4</ServiceId>
</Service>
<Service>
<Id>5</Id>
<Name>WheelChair</Name>
<ServiceId>5</ServiceId>
</Service>
<Service>
<Id>6</Id>
<Name>Excursion Limo</Name>
<ServiceId>6</ServiceId>
</Service>
<Service>
<Id>7</Id>
<Name>Hummer</Name>
<ServiceId>7</ServiceId>
</Service>
<Service>
<Id>8</Id>
<Name>White Limo</Name>
<ServiceId>8</ServiceId>
</Service>
<Service>
<Id>9</Id>
<Name>Bus (56 Pass.)</Name>
<ServiceId>9</ServiceId>
</Service>
<Service>
<Id>13</Id>
<Name>Bus (24 Pass.)</Name>
<ServiceId>9</ServiceId>
</Service>
<Service>
<Id>14</Id>
<Name>Bus (42 Pass.)</Name>
<ServiceId>9</ServiceId>
</Service>
<Service>
<Id>19</Id>
<Name>Bus (28 Pass.)</Name>
<ServiceId>9</ServiceId>
</Service>
<Service>
<Id>20</Id>
<Name>Bus (36 Pass.)</Name>
<ServiceId>9</ServiceId>
</Service>
<Service>
<Id>21</Id>
<Name>Bus (54 Pass.)</Name>
<ServiceId>9</ServiceId>
</Service>
<Service>
<Id>10</Id>
<Name>Limo Bus</Name>
<ServiceId>10</ServiceId>
</Service>
<Service>
<Id>16</Id>
<Name>School Bus (65 Pass.)</Name>
<ServiceId>11</ServiceId>
</Service>
<Service>
<Id>17</Id>
<Name>School Bus (66 Pass.)</Name>
<ServiceId>11</ServiceId>
</Service>
<Service>
<Id>18</Id>
<Name>School Bus (78 Pass.)</Name>
<ServiceId>11</ServiceId>
</Service>
<Service>
<Id>-100</Id>
<Name>DAR</Name>
<ServiceId>12</ServiceId>
</Service>
</ServiceDetails>
</Search>



ar colModelPrefService;
var dsPrefService;
var grdPrefService;// = new Ext.grid.GridPanel({
//store: dsPrefService,
//cm: colModelPrefService,
// height: 190,
// border: true,
// hidden: true
//});
function prefServiceCheckBox(val,param,record) {

return '<input type="checkbox" id="chk' +val+ record.data["Id"] + '" />';
}
colModelPrefService = new Ext.grid.ColumnModel([
{ header: "Id", sortable: true, width: 50, dataIndex: 'Id' },
{ header: "FirstName", sortable: true, width: 50, dataIndex: 'FirstName' },
{ header: "LastName", sortable: true, width: 50, dataIndex: 'LastName' },
{ header: "Id", sortable: true, width: 50, dataIndex: 'AllowOther' },
{ header: "", value: 1, sortable: true, renderer: function(v, params, record) { return prefServiceCheckBox(v, params, record); }, width: 50 }
]);

function AddPrefService(event) {
document.getElementById('divService').innerHTML = ''

dsPrefService = new Ext.data.Store({
url: "employee/events.aspx?From=GetEmployeePrefService?1=1",
reader: new Ext.data.XmlReader({ record: 'Service' },
[
{ name: 'Id'},
{ name: Name},
{ name: ServiceId}
]
)
});
dsPrefService.load();

grdPrefService = new Ext.grid.GridPanel({
store: dsPrefService,
cm: colModelPrefService,
height: 190,
border: true,
renderTo: document.getElementById('divService')
});
ShowWindowPrefService();
}
var winPrefService;
var btnFirst1 = new Ext.Button({
fieldLabel: 'First',
text: '|<',
id: 'btnFirst',
name: 'btnFirst',
//autoWidth: false,
width: 250,
//autoHeight:false,
height: 500,
handler: FirstEmployee,
clickEvent: 'mousedown'
});

function ShowWindowPrefService() {
// create the window on the first click and reuse on subsequent clicks
if (!winPrefService) {
winPrefService = new Ext.Window({
applyTo: 'divPrefService',
layout: 'fit',
width: 900,
height: 500,
closeAction: 'hide',
y: 40,
plain: true,
modal: true,
items: [grdPrefService]
});
}
winPrefService.show();
}

function SavePrefService()
{ }

Condor
13 Sep 2010, 11:41 PM
I don't understand the question. Your XML has a fixed layout, so why would you want dynamic fields and or columns?

nikhilesh
14 Sep 2010, 3:58 AM
Some Time my XML layout changed according to time.
Some New tag added to my xml

Condor
14 Sep 2010, 5:07 AM
You could create fields from the tags inside the ServiceDetails element.

You could also create columns, but they would have the name of the tags (e.g. ServiceId). Is that really what you want?