Connecting with mysql file...and facing problem

Hi all
I am a starter on webix.

when i am using url:“data.php”; < actually tested it independently by using “echo json_encode($myjsonarray);” > nothing is coming in dtable view.
json string is correctly created…

Do I need to add some connectors/config file
Please someone give some clear view on this.

Thanks in advance
Ajay Bramhe
New Delhi, India

If you are loading the data.php file in the separate window of a browser, is it shows the correct json output ?

Also, you need to provide columns config for datatable or use autoConfig:true to enable auto-configuration in the datatable.

The JSON-Response has to match this pattern:

{
  data: [{
    id: 1,
    prop1: 'foo'
  },{
    id: 2,
    prop2: 'bar'
  }]
}

In case you need to parse cursor information, you also need the pos and total_count properties.

{
  pos: 0,
  total_count: 1234,
  data: [{
    id: 1,
    prop1: 'foo'
  },{
    id: 2,
    prop2: 'bar'
  }]
}

EDIT: syntax highlighting

[
[{“id”:“1”,“menu_name”:“Frontdesk”}],
[{“id”:“2”,“menu_name”:“Booking”}],
[{“id”:“3”,“menu_name”:“Membership”}],
[{“id”:“4”,“menu_name”:“Academics”}]
]

I am getting response like this. the outer most is not a “{ }”

In the view:datatable i am writing following code:

Still my records not showing.

Kindly advice.

Got trimmed in the above comment box to putting inside remark.

div id=“ajbbox2” style=“width:1000px;height:200px;” /div

Got trimmed again…
Last try…i hope this will work.

Hi,

The format of your json data is incorrect:

http://docs.webix.com/datatable__supported_data_types.html#json

Please check DataTable demos (“samples” folder in Webix package), for example that one:

webix/samples/15_datatable/01_loading/09_config_xml.html

PS:
you can put your code between ~~~js and ~~~ to get the formatted code in the message.

PHP-Code Sample

/* result data array needs to be wrapped by "response" */
$response['data'] = $myjsonarray;
echo json_encode($response);

@maria: thanks for the syntax-highlighting hint.

@bramhe: look at the comments

/* this is the response, that you posted, wrong pattern.
 * this looks like you had an array on the first level
 * and each element of that array looks like an array with on object (wrong)
 */
[
    [{
        "id":"1",
        "menu_name":"Frontdesk"
    }],
    [{
        "id":"2",
        "menu_name":"Booking"
    }],
    [{
        "id":"3",
        "menu_name":"Membership"
    }],
    [{
        "id":"4",
        "menu_name":"Academics"
    }]
]

/* this is the pattern that you need.
 * object on the first level with a "data" property.
 * data is supposed to be an array of objects (not an array of arrays)
 */
{
    "data": [{
        "id":"1",
        "menu_name":"Frontdesk"
    },{
        "id":"2",
        "menu_name":"Booking"
    },{
        "id":"3",
        "menu_name":"Membership"
    },{
        "id":"4",
        "menu_name":"Academics"
    }]
}

just had to check out the syntax highlighting :wink:

Thanks a lot @Maria & @Phill54_de

Still my view file is not showing the table contents.
@Phill54_de : I have corrected the JSON string.

view.php contains:


< div id="ajbbox" style="width:1000px;height:200px;"></div >
< script type="text/javascript" charset="utf-8">
var dtable = new webix.ui({
	id:"dtable",
	container:"ajbbox",
	view:"datatable",
	autoConfig:true,
	autowidth:true,
	autoheight:true,
	url:"data.php";
});
</script > 

data.php contains:

return json_encode($myjsonarray);

Still my view file is not showing the table contents.
Awaiting for response.

You are using autoConfig property. Does your json contain both “config” and “data” ?

Please check the following for more details:

http://docs.webix.com/samples/15_datatable/01_loading/09_config_xml.html

http://docs.webix.com/samples/15_datatable/01_loading/data/data-config.json

I want to access a table from MySQL Database.
My JSON string is creating which I am able to see if i directly load it ( i.e. http://localhost/mywebixapp/data.php ) using echo json_encode($myjsonstring); but when I replace echo with return and use the mytableview.php file to load the data.php using url:data.php then it’s not showing me data.

Still waiting for a perfect solution.

My JSON string is creating which I am able to see

Please check that the result generated by your “data.php” corresponds with the DataTable data format.

Still waiting for a perfect solution.

The samples for Datatable contains a lot of the samples with json data loading. And possibly the following article will help: