cancel
Showing results for 
Search instead for 
Did you mean: 

Query template returning "object object " with ajax call.

Former Member
0 Kudos

Hi Experts,

I called the xacute query in ajax and tried to bind with sap ui table.

But I could not get json data from query template,Instead it ruturning result as [object,object],[object,object],[object,object]

With static data Ui5 table is working fine but if bind it  following way is  working .

Pls help me to resolve it.

var oModel = new sap.ui.model.json.JSONModel();

$.ajax({

   type: "POST",

url:'http://172.25.7.21:50000/XMII/Illuminator?QueryTemplate=Test/UI5/GetMaterialXacute&Content-Type=text...',  

success: function (data) {

alert("ok"+data);

var rows = data.Rowsets.Rowset[0].Row;

alert("rows"+rows);// returning object...... instead of actual results...

oModel.setData({modelData: rows});

  oTable.setModel(oModel);

  oTable.bindRows("/modelData");

},

error: function (err) {

    alert("Local error callback.");

  }     

     });//ajax close  

Regards,

Raj.

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member185280
Active Contributor
0 Kudos

Your alert outputs '[object]' etc because rows var is an object. Google "json to string" for ways to look at the content of your object.

Former Member
0 Kudos

HI Christian/Swarrop,

I could see the data if I display by converting with function decodeURIComponent($.param(data));

But I can bind it. Can you pls guid me..

$.ajax({

   type: "POST",

url:'http://Localhost:50000/XMII/Illuminator?QueryTemplate=Test/UI5/GetMaterialXacute&Content-Type=text/j...',  

success: function (data) {

alert("success");

var rows = data.Rowsets.Rowset[0].Row;

var Mat = data.Rowsets[Rowset][0][Row][0][MatNo];

//alert("rows"+data.Rowsets.Rowset[0]);

//var result = Y.QueryString.stringify(data);

var result =decodeURIComponent($.param(data));    // it is giving results in Rowsets[Rowset][0][Row][0][MatNo]  format

alert("result" +result);

oModel.setData({modelData: rows});         // binding in this way

  oTable.setModel(oModel);

  oTable.bindRows("/modelData");

},

Regards,

Bikshapathi.

swaroop_anasane
Active Contributor
0 Kudos

Hi Raj,

You have correctly set bindRows property. You need to now bind individual columns using text:"{MatNo}".

Regards,

Swaroop

Former Member
0 Kudos

Hi Swaroop,

Can you pls let me know how do I bind the individual columns...

As I could not get the individual columns from jquery...

Regards,

Bikshapathi.

swaroop_anasane
Active Contributor
0 Kudos

Hi Raj,

Please refer:

SAPUI5 SDK - Demo Kit

use something like shown below:

Create a column -

var oColumn = new sap.ui.table.Column({

label: new sap.ui.commons.Label({text: "Material No."}),

template: new sap.ui.commons.TextView().bindProperty("text", "MatNo"),

width: "200px"

});

Add this column to your table:

oTable.addColumn(oColumn);

Thanks,

Swaroop

swaroop_anasane
Active Contributor
0 Kudos

Hi Raj,

How are you binding the columns?

Basically, data.Rowsets.Rowset[0].Row gives json output only. You need to bound elements using names you get under object[]of the row.

Let's say a column in Rowset[0] is "name", then columns in ui.table should be binded as "{name}".

Hope this helps.

Regards,

Swaroop