use two or more tables from database in editor
use two or more tables from database in editor

I use codeigniter to create editor datatables, it was normal for one table, but when i use two tables, there problem in ajax, here is model.
public function getNdsar2020($post)
{
// Build our Editor instance and process the data coming from _POST
Editor::inst( $this->editorDb, 'ndsar2020' )
->fields(
Field::inst( 'no_ndsar' ),
Field::inst( 'tgl_ndsar' ),
// ->validator( Validate::dateFormat( 'd/m/y' ) )
// ->getFormatter( Format::dateSqlToFormat( 'd/m/y' ) )
// ->setFormatter( Format::dateFormatToSql( 'd/m/y' ) ),
Field::inst( 'surat' ),
Field::inst( 'tgl_surat' ),
Field::inst( 'keterangan' ),
Field::inst( 'hal' )
)
->process( $_POST )
->json();
}
public function getPelanggan2020($post)
{
// Build our Editor instance and process the data coming from _POST
Editor::inst( $this->editorDb, 'pelanggan_2020' )
->fields(
Field::inst( 'nama_pelanggan' ),
Field::inst( 'idpel' ),
Field::inst( 'tarif_lama' ),
Field::inst( 'daya_lama' ),
Field::inst( 'tarif_baru' ),
Field::inst( 'daya_baru' ),
Field::inst( 'jumlah' ),
Field::inst( 'alamat' ),
Field::inst( 'daerah_kerja' ),
Field::inst( 'kontak' )
)
->process( $_POST )
->json();
}
}
****and then here my editorlib.****
public function process($post)
{
// DataTables PHP library
require dirname(__FILE__).'/Editor-PHP-1.9.2/lib/DataTables.php';
//Load the model which will give us our data
$this->CI->load->model('Sar_model');
//Pass the database object to the model
$this->CI->Sar_model->init($db);
//Let the model produce the data
$this->CI->Sar_model->getNdsar2020($post);
//Let the model produce the data
$this->CI->Sar_model->getPelanggan2020($post);
}
i check the ajax load result with jsonlint, and here is the problem .
Would you give me solution ??
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
It looks like you are dumping the JSON from both tables into the same response. If so, then yes, that will cause a problem because:
Can you show me how you are initialising the two tables on the client-side please? Are you using two different URLs or just a common one? I would typically suggest using different ones so it is easy to route them as needed on the server-side and respond only with the data needed for that request.
If you want to combine them together into a single Ajax request, then you need to use
->data()
rather than->json()
to get the data and then dump it out into JSON in your own output array.Allan
I'm a newbe,
this is the controller.
I use different url,
then here my script for ndsar2020.
and here my script for pelanggan2020
Collin, would you give me suggestion, how to create singel Ajax request, the use
-> data() to get the data and then dump it to JSON ??? I have searched various literature from yesterday, and no found solution
Sorry, I mean Allan...
You have the tables pointing to two different files:
and
Assuming they each return their own JSON object, that should be all that is needed. If they are both returning the data for both tables, that then is an error in the controller.
Allan
Thanks Allan,
So, the problem in the controller. What should i do now to clear last JSON data when i access new url ?
Solved,
I create new EditorLib file to make singel Ajax response. thanks Allan, you're just awsome.....