How to properly render Mjoin json result?
How to properly render Mjoin json result?
ziv@kpmbro.com
Posts: 73Questions: 28Answers: 4
Hi
I am running a Mjoin and all the data is fine, the only problem is that in the Mjoin column at the client side
i am getting [object Object] or an error.
fields json:
[
{
"label":"Geos",
"name":"general_data_countries[].iso_2_letter_code",
"type":"select"
}
]
columns json:
[
{
"data":"general_data_countries",
"render":"[, ].name"
}
]
Server-side:
$this->editor_instance->leftJoin( 'offers_target_geos', 'offers_target_geos.offer_id', '=', 'offers_main_table.id' )
->join(
Mjoin::inst( 'general_data_countries' )
->link( 'offers_main_table.id', 'offers_target_geos.offer_id' )
->link( 'general_data_countries.iso_2_letter_code', 'offers_target_geos.country_id')
->order( 'name asc' )
->fields(
Field::inst( 'iso_2_letter_code' )
->validator( 'Validate::required' )
->options( 'general_data_countries', 'iso_2_letter_code', 'name' ),
Field::inst( 'name' )
)
);
Ajax json:
[ {
"DT_RowId":"row_6",
"offers_main_table":{
"title":"bla bla",
"network_campaign_id":"bla bla",
"advertiser_id":"1",
"offer_payout":"12.75"
},
"general_data_countries":[
{
"iso_2_letter_code":"NL",
"name":"Netherlands"
},
{
"iso_2_letter_code":"RU",
"name":"Russia"
},
{
"iso_2_letter_code":"US",
"name":"United States"
}
]
}]
How should it be rendered?
Thanks
This discussion has been closed.
Answers
Could you try:
What you have above should work, but I wonder if it is encountering an issue with
[]
being the first part of the render...Allan
Hey Allan.
No it didnt worked...
still getting :
DataTables warning: table id=offers_main_table - Requested unknown parameter 'null' for row 0, column 23. For more information about this error, please see http://datatables.net/tn/4
any ideas ? Thanks
Could you run the debugger over the table and send me the debug code (six characters)?
Allan
Hi Allan, I sent it to your mail. Thanks
The debugger appears to suggest that the following is used:
rather than:
Is it possible that your modelling code is stripping the square brackets somewhere?
Allan
Yes Allan that was that, i had a clean string function that remove the '[ ]].
Now that i can see it i am trying to make that multi-select field so i try this:
I am getting this error:
"dataTables.editor.min.js:56 Uncaught Unable to automatically determine field from source. Please specify the field name. For more information, please refer to https://datatables.net/tn/11"
What am i missing?
Thanks
You need to use the
editField
option that we discussed in order to tell Editor which field it should edit when you click on that column.Allan
Hi Allan after installing the select2 it all works good except of the part when i press update i get this. (pic attached).
this comes out of the console:
My fields:
My columns:
What did I missed?
Thanks
I figure it out it was the Validator.
But still i get no result after updating ...
Allan do i need to use the getFormatter with the Mjoin?
somthing like :
You have the country name in the database do you not? There should be no need to use a
getFormatter
. You want it to get the 2 letter code and the name.What is the JSON return after an update, and what is the data that is being submitted? You will be able to find that using the network inspector tools in your browser.
Thanks,
Allan
Thanks Allan.
I am getting two answers short and long.
short:
I cant post the long answer it have to many chars, i will mail it to you.
Thanks