1

I'm developing a web application with jax-rs, i made a rest client with jquery. I'm getting the result as json or xml, then showing them to html table. To facilitate table, im using JqGrid library. My problem is, for example Jqgrid wants to json object like below ;

[
        {yaziNo:"1",yazar:"abc",yazi:"test",tarih:"2007-10-01"}, 
        {yaziNo:"2",yazar:"cdfe",yazi:"test2",tarih:"2007-10-01"},
        {yaziNo:"3",yazar:"cdfe",yazi:"test3",tarih:"2007-10-01"}, 
        {yaziNo:"4",yazar:"abc",yazi:"test",tarih:"2007-10-01"}, 
        {yaziNo:"5",yazar:"cdfe",yazi:"test2",tarih:"2007-10-01"}, 
        {yaziNo:"6",yazar:"abc",yazi:"test3",tarih:"2007-10-01"},
        {yaziNo:"7",yazar:"cdfe",yazi:"test",tarih:"2007-10-01"},
        {yaziNo:"8",yazar:"abc",yazi:"test2",tarih:"2007-10-01"}, 
        {yaziNo:"9",yazar:"abc",yazi:"test3",tarih:"2007-10-01"}     ]

But, returned JSON from my rest server those like below;

{"yazi":
[{"tarih":"26.01.2012","yazar":"sdasdadsadasda","yazi":"gdfgdfgd","yaziNo":"1756"},
{"tarih":"26.01.2012","yazar":"sdasdadsadasda","yazi":"gdfgdfgd","yaziNo":"1755"},
{"tarih":"26.01.2012","yazar":"sdasdadsadasda","yazi":"gdfgdfgd","yaziNo":"1754"},
{"tarih":"26.01.2012","yazar":"sdasdadsadasda","yazi":"gdfgdfgd","yaziNo":"1753"},
{"tarih":"26.01.2012","yazar":"sdasdadsadasda","yazi":"gdfgdfgd","yaziNo":"1752"}]
}

How can i delete the "yazi" node but keeping inside.

edited:

jQuery("#list27").jqGrid({
    url:'http://localhost:43842/KodcuComRESTful/kodcuRS/yazilar',
    datatype: "json",
    height: 255,
    width: 700,
    jsonReader: {root: "yazi", repeatitems: false},
    colNames:['Yazi No','Yazar', 'Yazi', 'Tarih'],
    colModel:[
        {name:'yaziNo',index:'yaziNo', width:80, sorttype:"int"},
        {name:'yazar',index:'yazar', width:180}, 
        {name:'yazi',index:'yazi', width:370}, 
        {name:'tarih',index:'tarih', width:100, align:"right",sortype:"date"}
    ],
    rowNum:10,
    rowTotal: 2000,
    rowList : [20,30,50],
    loadonce:true,
    mtype: "GET", 
    rownumbers: true,
    rownumWidth: 40, 
    gridview: true, 
    pager: '#pager27',
    sortname: 'yaziNo',
    viewrecords: true,
    sortorder: "asc",
    caption: "Loading data from server at once"
});
Oleg
  • 220,925
  • 34
  • 403
  • 798
Rahman Usta
  • 716
  • 3
  • 14
  • 28

1 Answers1

3

I see no problem with the data returned from the server. You should just use jsonReader option of jqGrid which informs jqGrid how to read the data from the server response. For example

jsonReader: {root: "yazi", repeatitems: false}

UPDATED: The demo uses the exact JSON data which you posted and it displays the results in the grid. I used the JavaScript code which you posted and replaced only height: 255 to height: "auto" to have more compact results.

enter image description here

The only problem which I see in your code is the usage of full URL: url:'http://localhost:43842/KodcuComRESTful/kodcuRS/yazilar'. Because of same origin policy restriction one can't get JSON data per Ajax from another source as the same site and port. So in case of usage datatype: "json" you should always use relative URL path like url:'/KodcuComRESTful/kodcuRS/yazilar' for example.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks again Oleg, I fully rearranged my code, i wanna delete, add, update operations. i added add, delete, edit buttons in the left of pager bar, but i dont know how i implement /POST or /DELETE actions with jqGrid. I can do it with pure ajax functions, but i think jqGrid does best? – Rahman Usta Jun 25 '12 at 18:05
  • I think JqGrid best, but documentation is bad. – Rahman Usta Jun 25 '12 at 18:11
  • @RahmanUsta: I agree that many parts of jqGrid documentation are written only as a reference for persons who already knows jqGrid. There are no good introduction for the beginners. The next problem with implementation of Add/Edit/Delete operations has another important aspect: all the features will be implemented *on the server*. So you need code examples in the language and in the framework which you use. There are too many options on the server side. I don't know which one you use. – Oleg Jun 25 '12 at 19:54
  • Im using an stateless EJB for Restful endpoint with Java EE Jax-RS. I've sent u an email whats my problem. I read your post @ [link]http://www.trirand.com/blog/?page_id=393/feature-request/rest-support/[/link], its briefly that ; params.url += '/sil/' + encodeURIComponent(postdata);, post data produce row id, but i wanna get row's primary id.sil for delete. i tried postdata.yaziNo then i couldnt get it. – Rahman Usta Jun 25 '12 at 20:35
  • @RahmanUsta: I use ASP.NET, so I can't directly help you. You can find some additional information about RESTful services [here](http://stackoverflow.com/a/7365228/315935), [here](http://stackoverflow.com/a/9904338/315935) and [here](http://stackoverflow.com/a/9923417/315935). You should implement one feature after another. You can start with Edit or Delete. The problem with "primary id" exist probably because you *fill* the grid without `id`. If `yaziNo` contains unique values you can add `key: true` to the column definition. Then the rowid will be used from the `yaziNo` column. – Oleg Jun 25 '12 at 20:49
  • Thanks a lot again Oleg, you helped me so much. i did Delete function now. – Rahman Usta Jun 25 '12 at 20:55
  • @RahmanUsta: You are welcome! I'm glad to hear that I could help you. – Oleg Jun 25 '12 at 20:57
  • How can i customize the for example add and edit popup's form. When i click to add button, only appearing me Submit and Cancel button, No form elements. The same thing for edit button too. – Rahman Usta Jun 25 '12 at 21:30
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/13015/discussion-between-rahman-usta-and-oleg) – Rahman Usta Jun 25 '12 at 21:33