PDA

View Full Version : DataView store.save() Problem



phill54
25 Aug 2010, 3:54 AM
Hi,

It seems that I can't change data of a store as long as it is being displayed by a dataview. If I try to do so, ExtJS causes an Error:



fileName: "http://development:9287/ext/ext-all.js"
lineNumber: 7
message: "g is undefined"
name: "TypeError"
stack: "(0,null,true)@http://development:9287/ext/ext-all.js:7 ([object Object],[object Object],"edit")@http://development:9287/ext/ext-all.js:15 ([object Object],[object Object],"edit")@http://development:9287/ext/ext-all.js:7 ("update",[object Object],[object Object],"edit")@http://development:9287/ext/ext-all.js:7 ([object Object])@http://development:9287/ext/ext-all.js:15 ()@http://development:9287/ext/ext-all.js:15 ("name","new Data")@http://development:9287/ext/ext-all.js:15 (-2)@http://development:9287/dataviewtest.js:30 "
To isolate the error, I created a code example consisting out of 3 files:
dataviewtest.html (initial website to show, plz open javascript console to see the error)


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ExtJS DataView Test</title>
<link href="/ext/resources/css/ext-all.css" media="screen" rel="stylesheet" type="text/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" src="/dataviewtest.js"></script>
</head>
<body>
<script language="JavaScript" type='text/JavaScript'>
Ext.onReady(function() {
var dvt = DataViewTest.start();
dvt.panel.render('data-view-test-target');
});
</script>
<div id="data-view-test-target"></div>

<div id="data-view-test-xtemplate" class="x-hidden">
<tpl for=".">
{id} - {name}<br/>
</tpl>
</div>

</body>
</html>
dataviewtest.php - jsonstore url


<?php
$response['success'] = true;
$response['message'] = 'loaded';
$response['data'][0]['id'] = 0;
$response['data'][0]['name'] = 'Data';
$response['data'][1]['id'] = 1;
$response['data'][1]['name'] = 'visualized by';
$response['data'][2]['id'] = 2;
$response['data'][2]['name'] = 'ExtJS';
$response['data'][3]['id'] = 3;
$response['data'][3]['name'] = 'DataView';
$response['data'][4]['id'] = 4;
$response['data'][4]['name'] = 'Object';


echo json_encode($response);
?>
dataviewtest.js code to create the error


Ext.ns('DataViewTest');

DataViewTest.start = function () {
var store = this.getStore();
var xtpl = this.getXTemplate();

// if you do not create a dataview, the onLoad event on the store works without any problems.
var dv = new Ext.DataView({
store: store,
tpl: xtpl,
autoHeight:true
});
var panel = this.getPanel();
panel.add(dv);

store.on('load', function (store, records, options) {
setTimeout(DataViewTest.causesError(store), 2000);
}, this);

store.load();



return {
panel: panel
};
}
DataViewTest.causesError= function (store) {
return function () {
try {
var rec = store.getAt(0);
rec.set('name','new Data');
} catch (e) {
console.log(e);
throw new Error('Its not possible to update records of a store while the data of the store is represented in a dataview!');
}
}
}

DataViewTest.getStore = function () {
var store = new Ext.data.JsonStore({
url: 'dataviewtest.php',
root: 'data',
idProperty: 'id',
fields: [,
{name:'id', type: 'int'},
{name:'name', type:'string'}
]
});
return store;
}
DataViewTest.getXTemplate = function () {
var tpl = new Ext.XTemplate.from('data-view-test-xtemplate');
return tpl;
}

DataViewTest.getPanel = function () {
var panel = new Ext.Panel({
title : 'DataViewTest',
layout: 'anchor',
autoHeight: true,
width: 400
});
return panel;
}
Is this a Bug? Is there a common workaround for that? This is only a small example - but I have a large application with several DataViews attached to the same store and every store.save() event causes trouble because of this.

Thanks in advance!

phill54
26 Aug 2010, 12:22 AM
Noone can help? :(

phill54
27 Aug 2010, 2:29 AM
I expect this to be the solution. I'll report if it wasn't.

http://www.sencha.com/forum/showthread.php?101022-SOLVED-Manipulating-a-DataView-on-store-update&p=474436&highlight=record.beginEdit#post474436

phill54
27 Aug 2010, 3:30 AM
Found the solution:
http://www.sencha.com/forum/showthread.php?94882-Dataview-has-error-on-store-record-update.

DataView and Template where missing the itemSelector