Rss Feed

welcome to my space

finding the rowindex

March 14th, 2010 by , under nnmj.com.

  • hi
    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).


  • You put it in the wrong spot. Put it in the field definition. The mappings in the reader just tells it where to find stuff.


    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.


  • http://extjs.com/deploy/dev/docs/?class=Ext.data.Store&member=indexOfId


    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)


  • The ID will be whatever you send it as.


  • Ah, XML. It will be a string then.


    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]


  • but it's not field , it's the id
    you mean ?

    {id: 'mid', type: 'numeric'}

    I thought it would numeric by default


  • Ah, XML. It will be a string then.


  • Yes, when declaring a field there is a 'type' option.


  • The id is a field, same as everything else. You just point out to the reader that it should be used as an id.

    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"


  • I found the issue,
    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.


  • The ID is not a field, it has no converter, just a config of the reader telling it what DomQuery selector to use to grab the ID.


  • Why is that the case?

    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.


  • You put it in the wrong spot. Put it in the field definition. The mappings in the reader just tells it where to find stuff.


  • The ID will be whatever you send it as.


    hm..., not sure about it,
    it reads of an XML, (x), how can it be sent as anything in XML

    after ID is set in the reader, then it's available as a string after the datastore is loaded..


  • Read the docs:


    # type : String
    (Optional) The data type for conversion to displayable value. Possible values are

    * auto (Default, implies no conversion)
    * string
    * int
    * float
    * boolean
    * date


  • Read the docs:

    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


  • The ID is not a field, it has no converter, just a config of the reader telling it what DomQuery selector to use to grab the ID.

    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.


  • The id is a field, same as everything else. You just point out to the reader that it should be used as an id.


  • Well, you can have a field based on the ID property which is a numeric field.

    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.


  • http://extjs.com/deploy/dev/docs/?class=Ext.data.Store&member=indexOfId







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about finding the rowindex , Please add it free.