-
1 Sep 2011 6:02 AM #1
RowNumberer and Drag Drop
RowNumberer and Drag Drop
REQUIRED INFORMATION Ext version tested:
- Ext 4.0 rev 2
- any
- in a grid with a rownumberer column when adding a record the index doesn't get updated and repeat a numberScreenshot-DNA2Mongo! - DNA2 Form Editor - Mozilla Firefox.png
- create 2 grids with DD and a rowNumberer column
- drop an item.
- Row numbers getting updated on drop
- repeated number appear instead of reindexing
- not provided
- only default ext-all.css
- custom css (include details)
- any
-
2 Sep 2011 1:48 PM #2
Please provide a test case that demonstrates the issue and we will do our best to investigate it.
-
5 Sep 2011 7:41 AM #3
Ok the problem seems to be realted to the copy:true option in one of the grids
This is the dbd_grid_to_grid.js code toked from the examples and modified to reproduce the error:
Code:/* This file is part of Ext JS 4 Copyright (c) 2011 Sencha Inc Contact: http://www.sencha.com/contact GNU General Public License Usage This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact. */ Ext.require([ 'Ext.grid.*', 'Ext.data.*', 'Ext.dd.*' ]); Ext.define('DataObject', { extend: 'Ext.data.Model', fields: ['name', 'column1', 'column2'] }); Ext.onReady(function(){ var myData = [ { name : "Rec 0", column1 : "0", column2 : "0" }, { name : "Rec 1", column1 : "1", column2 : "1" }, { name : "Rec 2", column1 : "2", column2 : "2" }, { name : "Rec 3", column1 : "3", column2 : "3" }, { name : "Rec 4", column1 : "4", column2 : "4" }, { name : "Rec 5", column1 : "5", column2 : "5" }, { name : "Rec 6", column1 : "6", column2 : "6" }, { name : "Rec 7", column1 : "7", column2 : "7" }, { name : "Rec 8", column1 : "8", column2 : "8" }, { name : "Rec 9", column1 : "9", column2 : "9" } ]; // create the data store var firstGridStore = Ext.create('Ext.data.Store', { model: 'DataObject', data: myData }); // Column Model shortcut array var columns = [ Ext.create('Ext.grid.RowNumberer'), {text: "Record Name", flex: 1, sortable: true, dataIndex: 'name'}, {text: "column1", width: 70, sortable: true, dataIndex: 'column1'}, {text: "column2", width: 70, sortable: true, dataIndex: 'column2'} ]; // declare the source Grid var firstGrid = Ext.create('Ext.grid.Panel', { multiSelect: true, viewConfig: { copy:true, plugins: { ptype: 'gridviewdragdrop', dragGroup: 'firstGridDDGroup', dropGroup: 'secondGridDDGroup' }, listeners: { drop: function(node, data, dropRec, dropPosition) { var dropOn = dropRec ? ' ' + dropPosition + ' ' + dropRec.get('name') : ' on empty view'; Ext.example.msg("Drag from right to left", 'Dropped ' + data.records[0].get('name') + dropOn); } } }, store : firstGridStore, columns : columns, stripeRows : true, title : 'First Grid', margins : '0 2 0 0' }); var secondGridStore = Ext.create('Ext.data.Store', { model: 'DataObject' }); // create the destination Grid var secondGrid = Ext.create('Ext.grid.Panel', { viewConfig: { plugins: { ptype: 'gridviewdragdrop', dragGroup: 'secondGridDDGroup', dropGroup: 'firstGridDDGroup' }, listeners: { drop: function(node, data, dropRec, dropPosition) { var dropOn = dropRec ? ' ' + dropPosition + ' ' + dropRec.get('name') : ' on empty view'; Ext.example.msg("Drag from left to right", 'Dropped ' + data.records[0].get('name') + dropOn); } } }, store : secondGridStore, columns : columns, stripeRows : true, title : 'Second Grid', margins : '0 0 0 3' }); //Simple 'border layout' panel to house both grids var displayPanel = Ext.create('Ext.Panel', { width : 650, height : 300, layout : { type: 'hbox', align: 'stretch', padding: 5 }, renderTo : 'panel', defaults : { flex : 1 }, //auto stretch items : [ firstGrid, secondGrid ], dockedItems: { xtype: 'toolbar', dock: 'bottom', items: ['->', // Fill { text: 'Reset both grids', handler: function(){ //refresh source grid firstGridStore.loadData(myData); //purge destination grid secondGridStore.removeAll(); } }] } }); });
-
5 Sep 2011 3:10 PM #4
I wouldn't really classify this as a bug. The RowNumberer works by attaching a renderer to that column. This means that for the numbering to be correct all rows in the active view would need to be redrawn.
As a consequence, this means the row numberer would need to listen to various events and could possibly trigger the view to refresh prematurely. In this case it is better for you to manually refresh the grid view when your operation has completed.Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
6 Sep 2011 5:46 AM #5
Hi evan, thanks for the reply, now, how do i refresh the grid when dd (may be a noob question) but mygrid.getView().refresh() didn't do the trick.
Thanks in advance.
Juan
-
6 Sep 2011 10:40 AM #6
Evan some more info, this unexpected behaviour only happens with data loaded thru proxy, if the data was directly added to the store via 'data' propertry then the rownumberer works as expected
I provide you this aditional example:
I modified the xml-grid.js to have a rowNumberer and a store with id (wich i could fetch thru Ext.getStore
then in the console:Code:/* This file is part of Ext JS 4 Copyright (c) 2011 Sencha Inc Contact: http://www.sencha.com/contact GNU General Public License Usage This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact. */ Ext.require([ 'Ext.data.*', 'Ext.grid.*' ]); Ext.onReady(function(){ Ext.define('Book',{ extend: 'Ext.data.Model', fields: [ // set up the fields mapping into the xml doc // The first needs mapping, the others are very basic {name: 'Author', mapping: 'ItemAttributes > Author'}, 'Title', 'Manufacturer', 'ProductGroup' ] }); // create the Data Store var store = Ext.create('Ext.data.Store', { id:'store1', model: 'Book', autoLoad: true, proxy: { // load using HTTP type: 'ajax', url: 'sheldon.xml', // the return will be XML, so lets set up a reader reader: { type: 'xml', // records will have an "Item" tag record: 'Item', idProperty: 'ASIN', totalRecords: '@total' } } }); // create the grid var grid = Ext.create('Ext.grid.Panel', { store: store, columns: [ Ext.create('Ext.grid.RowNumberer'), {text: "Author", flex: 1, dataIndex: 'Author', sortable: true}, {text: "Title", width: 180, dataIndex: 'Title', sortable: true}, {text: "Manufacturer", width: 115, dataIndex: 'Manufacturer', sortable: true}, {text: "Product Group", width: 100, dataIndex: 'ProductGroup', sortable: true} ], renderTo:'example-grid', width: 540 }); });
Ext.getStore('store1').insert(2,{ Author : "RRRRRR", Title : "AAAAAAAAa"})
voilá!
Screenshot-XML Grid Example - Mozilla Firefox.jpg
I was reading the rowNumberer source and I don't understand why you return:
instead of:Code:return store.indexOfTotal(record) + 1;
if I modify RowNumerer with the line above it works every timeCode:return rowIdx+ 1;
-
2 Oct 2011 11:47 PM #7
In my case this way help:
This will update numbers in RowNumberer.Code:yourGrid.columns[0].doSort();
-
5 Dec 2011 11:58 PM #8
Looks like we can't reproduce the issue or there's a problem in the test case provided.


Reply With Quote