PDA

View Full Version : setDirty not marking a new record dirty



netemp
12 Jul 2012, 4:09 AM
Below is test case in which new records are getting added to grid.

For adding these records, there is button - Add. In the handler of the button, model instances are created and inserted in the grid store.

The issue is, that these new records don't appear dirty!

Even if we use setDirty() for the newly added record, the red mark does not appear.

Could someone guide that what could be the issue behind this?



<html>
<head>
<title>Test</title>
<link rel='stylesheet' href='resources/extjs/resources/css/ext-all.css' />
<script type='text/javascript' src='resources/extjs/ext-all-dev.js'></script>
<script type='text/javascript'>

//Defining the model below
Ext.define('PortRotationGridModel',{
extend:'Ext.data.Model',
fields:[
{type: 'int', name: 'seqNo'},
{type: 'string', name: 'portCode'},
{type: 'string', name: 'portName'}
]
});

//Below is the function which will be returning the grid when called
function getGrid(){

//Initial data at the store
var data = [{"portCode":"PC 1","portName":"PN 1","seqNo":1},{"portCode":"PC 2","portName":"PN 2","seqNo":2},{"portCode":"PC 3","portName":"PN 3","seqNo":3},{"portCode":"PC 4","portName":"PN 4","seqNo":4},{"portCode":"PC 5","portName":"PN 5","seqNo":5}];

//Store object
var storeObj = Ext.create('Ext.data.Store', {
model: 'PortRotationGridModel',
data : data
});

//Creating the grid
var getPortRotationGrid = Ext.create('Ext.grid.Panel', {
store: storeObj,
id:'gridId',
renderTo:Ext.getBody(),
width:600,
height:500,
columns: [ {
flex: 1,
align: 'center',
dataIndex: 'seqNo',
header:'New'
},{
flex: 2,
minWidth: 50,
align: 'center',
dataIndex: 'portCode',
header:'Code'
},{
flex: 3,
minWidth: 100,
sortable: true,
dataIndex: 'portName',
header:'Name'
}],
tbar:[
{
text:'Add',
handler:function(){

//Creating the Model Instance below
var rec = Ext.create('PortRotationGridModel',{
portCode:'New Code',
portName:'New Name',
seqNo:1000
});

var gridStore = Ext.getCmp('gridId').getStore();


//Inserting in the grid store below
gridStore.insert(0, rec);

//Setting the record as dirty
gridStore.getAt(0).setDirty();
}
}
]
});
return getPortRotationGrid;
}
Ext.onReady(function(){
getGrid();//Calling the grid function here
});
</script>
</head>
<body>
</body>
</html>


Thanks for any help in advance.

PS: ExtJs version 4.1

Farish
12 Jul 2012, 5:18 AM
After using setDirty(), try to print store.getUpdatedRecords() on Firebug console. If it contains the records which you are setting dirty, then the function is working. The red flags are only shown for modified fields. If e.g. I have a record with 4 fields and 3 of them are displayed in the grid. Now if I change the 4th field of the record (the one which is not displayed in the grid), then the grid will not show any difference. The red flag will only appear when one of the visible fields has changed.

netemp
12 Jul 2012, 9:25 PM
Thanks for the post Farish.


The red flags are only shown for modified fields. If e.g. I have a record with 4 fields and 3 of them are displayed in the grid. Now if I change the 4th field of the record (the one which is not displayed in the grid), then the grid will not show any difference. The red flag will only appear when one of the visible fields has changed.

This is exactly what we are doing, that is, currently we first insert blank records and then we update them so that the red flag appears. But we were just wondering if there is some other way for it so that this effort gets saved down of first-insertion-then-updation and expected that using setDirty() we could mark a column/record forcefully dirty displaying the red flag.

But from your post it looks like that we shall have to continue with the same approach.

Farish
12 Jul 2012, 10:43 PM
there might be some other way to do it but may be I dont know it too.

theboulderer
6 Feb 2014, 5:14 AM
I know this is an old post but i wanted to do the same thing and figured it out. If you add the new record then get the grids view and refresh the new record will show up as edited with the red flags on each column:

grid.view.refresh();

This will do the trick so now you shouldn't have to add a blank record get it add the new data and mark it as dirty. Just add the new record marked as dirty and refresh the view. Hope this helps someone. :D


Thanks for the post Farish.



This is exactly what we are doing, that is, currently we first insert blank records and then we update them so that the red flag appears. But we were just wondering if there is some other way for it so that this effort gets saved down of first-insertion-then-updation and expected that using setDirty() we could mark a column/record forcefully dirty displaying the red flag.

But from your post it looks like that we shall have to continue with the same approach.