Error with edit button after add a wherecondition
Error with edit button after add a wherecondition
Hi, I have an error when I update my table with a edit button, my json data is empty, but i update with a setValue in editor.
My controller :
```
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;
// Build our Editor instance and process the data coming from _POST
$today = date("Y-m-d H:i:s");
$editor = Editor::inst( $db, 'llx_commandedet as comdet', 'rowid')
->fields(
Field::inst('com.rowid'),
Field::inst('p.ref'),
Field::inst('comdet.date_start')
->getFormatter( Format::dateSqlToFormat( 'd/m/Y' ) ),
Field::inst('com.ref'),
Field::inst('soc.nom'),
Field::inst('p.label'),
Field::inst('comdetex.kit_specifique')
->getFormatter( function ( $val, $data ) {
return $val ? 'Oui': 'Non';
}),
Field::inst('comdetex.date_retrait', 'date_retrait')
->getFormatter( Format::dateSqlToFormat( 'd/m/Y' ) )
->set(Field::SET_EDIT)
->setValue($today),
Field::inst('comdetex.fk_statut', 'statut')
->set( Field::SET_EDIT )
->setValue("3"),
Field::inst('comex.id_site', 'id_site'),
)
->leftJoin('llx_commande as com','com.rowid', '=', 'comdet.fk_commande')
->leftJoin('llx_commande_extrafields as comex','comex.fk_object', '=', 'com.rowid')
->leftJoin('llx_commandedet_extrafields as comdetex','comdetex.fk_object', '=', 'comdet.rowid')
->leftJoin('llx_societe as soc','soc.rowid', '=', 'com.fk_soc')
->leftJoin('llx_societe as point_relais','point_relais.rowid', '=', 'comex.fk_point_relais')
->leftJoin('llx_product as p','p.rowid', '=', 'comdet.fk_product')
->where('com.fk_soc', $user->id)
->where('comdetex.date_retrait', null)
->where('comex.id_site', $_POST['id_site'])
->process( $_POST )
->json();
And my table :
if ($_SERVER["REQUEST_METHOD"] == "POST" ) {
$id_site = $_POST["id_site"];
}
<?php
>
?>
var editor;
$(document).ready( function () {
editor = new $.fn.dataTable.Editor( {
language: {
url:"https://cdn.datatables.net/plug-ins/1.10.22/i18n/French.json"
},
ajax: {
url: '../../includes/datatable/controllers/point_relais.php',
type:'POST',
data: function (d) {
d.id_site = "<?= $id_site ?>";
}
},
table: '#commande',
i18n: {
create: {
button: "Nouveau",
title: "Créer nouvelle entrée",
submit: "Créer"
},
edit: {
button: "Modifier",
title: "Êtes vous sur de vouloir mettre à jour le statut de la commande?",
submit: "Confirmer"
},
remove: {
button: "Supprimer",
title: "Supprimer",
submit: "Supprimer",
confirm: {
_: "Etes-vous sûr de vouloir supprimer %d lignes?",
1: "Etes-vous sûr de vouloir supprimer 1 ligne?"
}
},
error: {
system: "Une erreur s’est produite, contacter l’administrateur système"
},
multi: {
title: "Plusieurs valeurs",
info: "Les éléments sélectionnés contiennent des valeurs différentes pour cette entrée. Pour modifier et mettre tous les éléments pour cette entrée pour la même valeur, cliquez ou appuyez ici, sinon ils vont conserver leurs valeurs individuelles.",
restore: "Annuler les modifications"
},
datetime: {
previous: 'Précédent',
next: 'Premier',
months: [ 'Janvier', 'Février', 'Mars', 'Avril', 'peut', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre' ],
weekdays: [ 'Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam' ]
}
},
fields: [
// {
// label: "Date retrait",
// name:"date_retrait",
// data:"date_retrait",
// type:"date",
// }
],
});
var table = $('#commande').DataTable({
language: {
url:"https://cdn.datatables.net/plug-ins/1.10.22/i18n/French.json"
},
ajax: {
url: '../../includes/datatable/controllers/point_relais.php',
type:'POST',
data: function (d) {
d.id_site = "<?= $id_site ?>";
}
},
pageLength: 20,
dom : 'BPirt',
columns: [
{targets: 0,
data: null,
defaultContent: '',
orderable: false,
className: 'select-checkbox' },
{data: 'p.ref'},
{data: 'comdet.date_start'},
{data: 'p.label'},
{data: 'id_site', className:"id_site", visible:false},
],
select: {
style: 'multi',
selector: 'td:first-child'
},
order: [[ 2, 'desc' ]],
responsive:true,
buttons: [{ extend: "edit", editor: editor, text: "Valider Commande(s) retirée(s)"}]
});
// $('#id_site').on( 'keyup', function () {
// table
// .columns(".id_site")
// .search( this.value )
// .draw();
// } );
} );
</script>
<?php
if(!empty($_POST['id_site'])){
Article | Date Prévisionnelle | Produit | Site |
---|
Replies
Just to confirm, if you remove the:
then you don't get any errors?
What version of the Editor PHP libraries are you using please (so I can check the line numbers)?
Allan
Hi,
Sorry for the time. Yes I haven't any errors.
I use the Editor 1.9.6
Clement
Those errors are all where Editor tries to access the
data
sent by the client-side.Could you possibly try:
instead of your three ->where() lines please?
I don't really know if that will resolve it, but equally, to be honest, I don't know why those three lines would disrupt the $_POST data!
Regards,
Allan
I try but i have a json invalid error
Clement
Hi Clement,
Sorry, you'll need:
I always forget that in PHP...!
Allan
I have the same error "Need to contact an administrator ..
Thank's aniway
Are you able to link to your page so we can take a look, please?
Colin
I can't, it's a customer area, with password access, sorry ...
Clement
What is the response from the server - does it contain an error message saying what the problem is? I might have missed some other daft syntax error...
Allan