finding the rowindex
March 14th, 2010 by , under nnmj.com.
I have a grid of values loaded from an xml eg
ID 1,2,3 (unique)
Name x,y,z
what I am trying to do is to automatically select a row, by users providing the ID of that job,
but can't seem to find an easy way to get to rowindex from one of the values (ID).
well, I am not sure,
this
reader: new Ext.data.XmlReader({
record: 'row',
id: 'mid'
}, [
{name: 'id', mapping: 'mid', type: 'int'},
{name: 'date', type: 'date', dateFormat: 'Y-m-d'},
'title', 'catname', 'username', 'iname', 'descr', 'lat', 'lon', 'zoom', 'url', 'image', 'isize', 'sname', 'ssize', 'edit'
])
will bring the same thing,
and this
reader: new Ext.data.XmlReader({
record: 'row'
}, [
{name: 'id', mapping: 'mid', type: 'int'},
{name: 'date', type: 'date', dateFormat: 'Y-m-d'},
'title', 'catname', 'username', 'iname', 'descr', 'lat', 'lon', 'zoom', 'url', 'image', 'isize', 'sname', 'ssize', 'edit'
])
gives IDs from "1001" upward instead of the original ids.
thanx,
that sort of the problem,
if this is data store :
http://img262.imageshack.us/img262/2286/dsgn1.th.jpg (http://img262.imageshack.us/my.php?image=dsgn1.jpg)
then with s being 18 (or any other number), the row is "-1"
ds.load({callback: function( r, options, success){
if(s){
alert(s);
alert(grid.getStore().getCount())
var row = grid.getStore().indexOfId(s);
alert(row);
grid.getSelectionModel().selectRow(row);
}
}});
even if I tried to get after the page is loaded it is still "-1"
Grid_UI.getDataSource().indexOfId(18);
(Grid_UI being the grid class and getDataSource returning the data store)
Now I have a huge, huge problem with this,
with the ID being a "string", sorting is also string wise,
that is if IDs are from 1-100
sorting is 1-10-100-2-etc.
[SOLVED]
you mean ?
{id: 'mid', type: 'numeric'}
I thought it would numeric by default
thnax but
{id: 'mid', type: 'numeric'}
definitely didn't work,
so I don't know how declare the id as numeric
can't seem to find anything about it in manual except that it is a "string"
it looks like a bug to me,
the problem is the "id" considered a string and not a number,
so like I mentioned this will not work :
Grid_UI.getDataSource().indexOfId(18);
but this works
Grid_UI.getDataSource().indexOfId("18");
with this being my datastore :
ds = new Ext.data.Store({
url: 'markers.php',
baseParams : {catid: cid},
reader: new Ext.data.XmlReader({
record: 'row',
id: 'mid',
totalRecords: '@total'
}, [
{name: 'mid', mapping: 'mid'},
{name: 'date', type: 'date', dateFormat: 'Y-m-d'},
'title', 'catname', 'username', 'iname', 'descr', 'lat', 'lon', 'zoom', 'url', 'image', 'isize', 'sname', 'ssize', 'edit'
])
});
is there anyways to have the type id being numeric.
Since he's not passing a convert method, then the convert method is set (to basically a variation of parseInt) since the type has been set.
In the XmlReader it calls convert automatically.
hm..., not sure about it,
it reads of an XML, (
after ID is set in the reader, then it's available as a string after the datastore is loaded..
# type : String
(Optional) The data type for conversion to displayable value. Possible values are
* auto (Default, implies no conversion)
* string
* int
* float
* boolean
* date
thanx
this throws an error before getting to the type part
ds = new Ext.data.Store({
url: 'markers.php',
baseParams : {catid: cid},
reader: new Ext.data.XmlReader({
record: 'row',
{id: 'mid' , type : 'int'},
totalRecords: '@total'
}, [
{name: 'mid', mapping: 'mid'},
{name: 'date', type: 'date', dateFormat: 'Y-m-d'},
'title', 'catname', 'username', 'iname', 'descr', 'lat', 'lon', 'zoom', 'url', 'image', 'isize', 'sname', 'ssize', 'edit'
])
});
of
invalid property id
{id: 'mid' , type : 'int'},n
then I think it's only logical for the type of the ID to be numeric,
for now I am just converting my numbers to string before I use them with "indexOfId(var)",
var += '';
but it would have been better if I didn't have to.
Just give the field a type in the Record definition, and it will sort fine.
A field which you may choose to call "id" is not the same thing as the Record ID. They may come from the same property, but the Record ID will not be converted. If you map it to a field, you can convert it.
#If you have any other info about this subject , Please add it free.# |