Check documentation for the latest version of dhtmlxSuite JSONDataConnector/DataConnector DHTMLX Docs

JSONDataConnector/DataConnector

Common

There are 2 connectors you can use for touch-oriented DHTMLX libraries (such as DataTable, DataStore):

  • DataConnector
  • JSONDataConnector

They both work the same way, but differ in type of returned data.

<?php 
require_once("../../connector/data_connector.php");
require_once("../../connector/db_sqlite.php");
 
if (!$db = sqlite_open('db', 0777, $sqliteerror)) {
    die($sqliteerror);
}
$data = new JSONDataConnector($db,"SQLite");
$data->render_table("users", "id", "name,age,city");
?>

DataConnector

DataConnector generates 'XML' data feed as in:

<data>
   <item id="1" title="War and Peace"  author="Leo Tolstoy"/>
   <item id="2" title="Hamlet"         author="William Shakespeare"/>
   <item id="3" title="Madame Bovary"  author="Gustave Flaubert"/>
</data>

JSONDataConnector

JSONDataConnector generates 'JSON' data feed as in:

[
   { id:"1", title:"War and Peace",    author:"Leo Tolstoy" },
   { id:"2", title:"Hamlet",           author:"Shakespeare" },
   { id:"3", title:"Madame Bovary",    author:"Gustave Flaubert" }
]

Adding tags/sections to data

Starting from version 1.5, there is a possibility to add the first child tags, sections to data returned by the connector. To add a tag(section), use method add_section.

DataConnector

For example, if you call add_section as follows:

$data = new JSONDataConnector($db,"SQLite");
$data->add_section("config", "some_data");
$data->add_section("config2", "<column>data1</column><column>data2</column>");

DataConnector produces the next data:

<data>
    <config>some_data</config>
    <config2><column>data1</column><column>data2</column></config2>
    <item id="1" attr1="qwe" attr2="asd" />
    <item id="2" attr1="qwe" attr2="asd" />
</data>

JSONDataConnector

If you call add_section as follows:

$data = new JSONDataConnector($db,"SQLite");
$data->add_section("config", "'some_data'");
$data->add_section("config2", "{ column1: 'data1'}");

JSONDataConnector produces the next data:

{
    data: [
      { 'id': '1', 'attr1':'qwe', 'attr2':'asd'},
      { 'id': '2', 'attr1':'qwe', 'attr2':'asd'}
    ],
    config: 'some_data',
    config2: { 'column1':'data1' },  
}

Simple Data Transfer

JSONDataConnector/DataConnector supports simplified protocol for CRUD requests.

  • get all data
 GET  data.php?action=get

server response - collection of json (xml) objects

  • get info for some specific record
 GET   data.php?action=get&id=123

response - json(xml) object

  • delete
 GET  data.php?action=delete
 POST id=123

server response - 'true'/'false'

  • insert
 GET  data.php?action=insert
 POST id=123&some=value&other=value

response on success

true
<new_id>

or

 false

on failed insert operation

  • update
 GET  data.php?action=delete
 POST id=123&some=value&other=value

response - 'true'/'false'

Back to top