2

I have a little problem, I need to load some json data to my grid, but I have specifical json format like this:

{"response":[
  76297,
  {"aid":66132303,"owner_id":30729520,"artist":"Шакира - Танго","title":"So objection!! I don't wanna be the exception to get a bit of your attention... I love you for free and I'm not your mother, but you don't even bother... Objections!! I'm tired of this triangle... GOT DIZZY DANCING TANGO&#3","duration":224,"url":"http:\/\/cs1663.vkontakte.ru\/u17640367\/audio\/ebde4092fde5.mp3","lyrics_id":"2203614"},
  {"aid":129159521,"owner_id":23962687,"artist":"Yann Tiersen","title":"Mother's Journey (Ennja Remix)","duration":281,"url":"http:\/\/cs6000.vkontakte.ru\/u97497795\/audio\/fb309491bc82.mp3","lyrics_id":"21301612","album":"21017129"},
  {"aid":81267321,"owner_id":673065,"artist":"Hurts","title":"Mother Nature","duration":170,"url":"http:\/\/cs4633.vkontakte.ru\/u673065\/audio\/d329378eb2d2.mp3","lyrics_id":"5693202"}]
}

So the first element of array is number of total records, and others are the records to load. If I try to load such records to my grid I have empty row at the bottom, what is a solution? Should I use some "custom" reader, how to implement it?

Luft-on
  • 179
  • 1
  • 13

1 Answers1

3

Yes. Most likely you would need to extend standard Json reader (Ext.data.reader.Json) to parse length first and start parsing records from the second item.

Update: It's quite easy to do actually.

  1. First you need to figure our place where standard reader doesn't behave the way you want it to behave. Add traces to standard reader class, to see what's going on. Most likely it will be somewhere around readResponse() method.

  2. Create your own reader class extending standard one. Simple inheritance.

  3. Override method you need with new logic.

ExtJs code is very well written and commented. I found it's quite interesting to read and understand it.

As a side note I would add that this task (extending existing ExtJs code with your functionality) is a huge help to better understand how ExtJs works inside and you will feel much more confortable working with ExtJs after that.

sha
  • 17,824
  • 5
  • 63
  • 98