Editor::inst and SSP::complex
Editor::inst and SSP::complex

Hello everyone!
I ask for help.
I want to combine 2 implementation options - Editor::inst and SSP::complex.
Each of them works separately, but if you can make a selection by where, then the delete and CheckBox functions stop working.
Here is a sample code:
staff.php
<?php
/*
* Example PHP implementation used for the index.html example
*/
// DataTables PHP library
include( "../lib/DataTables.php" );
// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;
require( "../lib/ssp.class.php" );
require("../lib/config.php");
$table = "hrna_clients";
$primaryKey = "client_id";
$columns = array(
array("db"=>"user_id","dt"=>"user_id"),
array("db"=>"client_id","dt"=>"client_id"),
...
array("db"=>"client_telegram_check","dt"=>"client_telegram_check")
);
$where = "user_id=1;";
//echo json_encode(SSP::complex($_POST, $sql_details, $table, $primaryKey, $columns, $where ) );
// Allow a number of different formats to be submitted for the various demos
$format = isset( $_GET['format'] ) ?
$_GET['format'] :
'';
if ( $format === 'custom' ) {
$update = 'n/j/Y';
}
else {
$update = "Y-m-d";
}
// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, "hrna_clients")
->fields(
Field::inst( 'user_id' ),
Field::inst( 'client_id' ),
...
Field::inst( 'client_telegram_check' )->setFormatter( function ( $val, $data, $opts ) { return ! $val ? 0 : 1; } )
)
->process( $_POST )
->json();
'''
and mypage.html
''' <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="shortcut icon" type="image/ico" href="http://www.datatables.net/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0, user-scalable=no">
<title>Editor example - Basic initialisation</title>
<link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.22/css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.6.5/css/buttons.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/select/1.3.1/css/select.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="../../css/editor.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="../resources/syntax/shCore.css">
<link rel="stylesheet" type="text/css" href="../resources/demo.css">
<style type="text/css" class="init">
</style>
<script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script type="text/javascript" language="javascript" src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.22/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/1.6.5/js/dataTables.buttons.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/select/1.3.1/js/dataTables.select.min.js"></script>
<script type="text/javascript" language="javascript" src="../../js/dataTables.editor.min.js"></script>
<script type="text/javascript" language="javascript" src="//cdn.datatables.net/plug-ins/1.10.19/sorting/datetime-moment.js"></script>
<script type="text/javascript" language="javascript" src="../resources/syntax/shCore.js"></script>
<script type="text/javascript" language="javascript" src="../resources/demo.js"></script>
<script type="text/javascript" language="javascript" src="../resources/editor-demo.js"></script>
<script type="text/javascript" language="javascript" class="init">
var editor; // use a global for the submit and return data rendering in the examples
$(document).ready(function() {
$.fn.dataTable.moment("M/D/YYYY");
editor = new $.fn.dataTable.Editor( {
ajax: "../../controllers/staff.php?format=custom",
table: "#example",
fields: [
{label: "user_id", name: "user_id" },
{label: "client_id", name: "client_id" },
...
{label: "client_telegram_check",name: "client_telegram_check", type: "checkbox", separator: "|", options: [ { label: "", value: 1 } ] }
]
} );
$('#example').DataTable( {
dom: "Bfrtip",
//processing: "true",
//serverSide: "true",
pageLength: "10",
ajax: "../../controllers/staff.php?format=custom",
columns: [
{ data: "user_id" },
{ data: "client_id" },
...
{ data: "client_telegram_check", render: function ( data, type, row ) {if ( type === 'display' ) { return '<input type="checkbox" class="editor-client_telegram_check">';} return data; }, className: "dt-body-center"},
],
select: {
style: 'os',
selector: 'td:not(:last-child)' // no row selection on last column
},
buttons: [
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor }
],
rowCallback: function ( row, data ) {
// Set the checked state of the checkbox in the table
$('input.editor-client_telegram_check', row).prop( 'checked', data.client_telegram_check == 1 );
}
} );
$('#example').on( 'change', 'input.editor-client_telegram_check', function () {
editor
.edit( $(this).closest('tr'), false )
.set( 'client_telegram_check', $(this).prop( 'checked' ) ? 1 : 0 )
.submit();
} );
} );
</script>
</head>
<body class="dt-example php">
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>user_id</th><th>client_id</th><th>client_telegram_check</th>
</tr>
</thead>
<tfoot>
<tr>
<th>user_id</th><th>client_id</th><th>client_telegram_check</th>
</tr>
</tfoot>
</table>
</body>
</html>'''
Please tell me how to properly combine the two conditions. The end goal is to conditionally select the user_id field by adding it as a condition in SSP :: complex
This question has accepted answers - jump to:
Answers
I'd say don't attempt to combine them. Editor's server-side processing implementation is every bit as capable (more so in fact) than the demo SSP class.
Information on how to apply a condition to the Editor PHP class can be found here.
Allan
It's not PHP Editor, but DataTables's
I want to use:
Allan, thanks, it's works, but i want to test SSP::complex can you help me?
Can we step back for a moment and just find out what you are trying to do? Editor’s PHP libraries work with server-side processing as well. I can’t think of any case where you would need to mix the two. I’m not clear on why you want to do that?
Allan