Hello, I read some topic, in particular this, without solution for my work.
So, I've create a PHP Function (NAME: server_side_array) with this code:
The output is
Then in TABLE (Name articles_list) VIEW I add this DATA PROVIDER: {var.jsonde:data_joined}
The INDEX EVENT is this:
My questions is:
Thank you for your reply
So, I've create a PHP Function (NAME: server_side_array) with this code:
$table = 'xijhd_cf_product_data-2';
// Table's primary key
$primaryKey = 'cf_id';
$columns = array(
array( 'db' => 'cf_id','dt' => 'arr_cf_id' ),
array( 'db' => 'p_description','dt' => 'arr_p_description' ),
array( 'db' => 'p_lotto', 'dt' => 'arr_p_lotto' ),
array( 'db' => 'g_tag', 'dt' => 'arr_g_tag' ),
array( 'db' => 'created','dt' =>'arr_created',
'formatter' => function( $d, $row ) {
return date( 'd-m-Y', strtotime($d));
}
)
);
// SQL server connection information
$sql_details = array(
'user' => 'root',
'pass' => '*********',
'db' => 'generaphoto',
'host' => 'localhost'
);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* If you just want to use the basic configuration for DataTables with PHP
* server-side, there is no need to edit below this line.
*/
require( 'vendor/DataTables/server-side/scripts/ssp.class.php' );
/*
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);
*/
$jdata1 = SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns );
$jdata = json_encode($jdata1);
$this->set("data_joined", $jdata);
echo $jdata;
The output is
{"draw":0,"recordsTotal":386,"recordsFiltered":386,"data":[{[mark]"arr_cf_id":"233","arr_p_description":"2020-01-01_1021","arr_p_lotto":"YZJ30EM","arr_g_tag":"sub1","arr_created":"03-02-2020"[/mark]},{"arr_cf_id":"232","arr_p_description":"2020-01-01_1021","arr_p_lotto":"YZJ30EM","arr_g_tag":"sub1","arr_created":"03-02-2020"},{"arr_cf_id":"231","arr_p_description":"2020-01-01_1021","arr_p_lotto":"YZJ30EM","arr_g_tag":"sub1","arr_created":"03-02-2020"},{"arr_cf_id":"230","arr_p_description":"2020-01-01_1021","arr_p_lotto":"YZJ30EM","arr_g_tag":"sub1","arr_created":"01-01-2020"},......
Then in TABLE (Name articles_list) VIEW I add this DATA PROVIDER: {var.jsonde:data_joined}
The INDEX EVENT is this:
{fn:server_side_array}
{view:articles_list}
My questions is:
- Is correct till now my work?
- what code I need to add in COLUMN LIST of TABLE VIEW to view arr_cf_id / arr_p_description / arr_p_lotto fields?
Thank you for your reply
Why can't you just use the read data action?
Why are you Json encoding something, just to then decode it again straight away?
You add the same code as when you're using read data to show things in the columns, could just look at the demos
Why are you Json encoding something, just to then decode it again straight away?
You add the same code as when you're using read data to show things in the columns, could just look at the demos
I tried this way because I would implement the server-side filter, like this
If is read data the way, I will try this.
If is read data the way, I will try this.
I have a similar question about using JSON as data source.
I have this JSON retrieved from a PostgreSQL DB.
How can I use it as a data source and show results in a table view like a "Read Data" function.
I have this JSON retrieved from a PostgreSQL DB.
How can I use it as a data source and show results in a table view like a "Read Data" function.
With {var.jsonde:attributename}
Function PHP "dados":
Event "index":
$dados = file_get_contents('http://painel.ufrb.edu.br/api/queries/242/results.json?api_key=Eutfx0CgjncKW7hFzB2svVIz1U43P1FHydS5NzDg');
$this->set("dados", $dados);
Event "index":
{fn:dados}View "setores":
{view:setores}
Data provider: {var:dados}Debug:
Columns list: nome:Nome
Column views: Nome:{var.jsonde:nome}
Array ( [option] => com_chronoconnectivity6 [cont] => manager [conn] => testejson )
Array ( [dados] => Array ( [returned] => [var] => ) )What´s wrong?
I don't see nome being used anywhere, wouldn't you want var.jsonde:dados ?
"nome" is a attribute of "dados"
"dados" has many attributes: nome, telefones, cidade, hierarquia, email
"dados" has many attributes: nome, telefones, cidade, hierarquia, email
{
"query_result": {
"retrieved_at": "2021-04-30T20:34:05.343Z",
"query_hash": "afa12ea7fbb668e5b17996fbca7943a5",
"query": "SELECT comum.unidade.id_unidade\nSIGLA,\n hierarquia,\n comum.unidade.nome,\n endereco,\n uf,\n cep,\n comum.municipio.nome cidade,\n comum.unidade.telefones,\n comum.unidade.email\n FROM comum.unidade\nINNER JOIN comum.municipio ON comum.municipio.id_municipio = comum.unidade.id_municipio\nWHERE comum.unidade.ativo = TRUE",
"runtime": 0.0334348678588867,
"data": {
"rows": [
{
"telefones": "3621-2350",
"nome": "COORD CRIACAO E INOVACAO",
"cidade": "CRUZ DAS ALMAS",
"hierarquia": ".648.336.342.909.",
"cep": "44380-000",
"endereco": "Av. Rui Barbosa, 710",
"uf": "BA",
"email": "cinova@ppgci.ufrb.edu.br ",
"sigla": 909
},
{
"telefones": "3621-2350",
"nome": "COORD CULTURA E UNIVERSIDADE",
"cidade": "CRUZ DAS ALMAS",
"hierarquia": ".648.336.343.849.",
"cep": "44380-000",
"endereco": "Av. Rui Barbosa, 710",
"uf": "BA",
"email": null,
"sigla": 849
},
dados.nome
This topic is locked and no more replies can be posted.