Inline edit to a table that changes databases on user select.
Inline edit to a table that changes databases on user select.

I have a project where I have one Editor table where the data changes in that table depending on which project the user selects. I am changing the data that is shown to the user in my editor table from a select drop-down list. The user will select which project they want to see and on selection, I am sending the variable to my server-side script and using that value to decide which table to pull data from. If there is not a user selection then the default table will show on the client-side. The problem that I am having is when the table data changes on the client-side from a user selection and I edit the table the change is taking place in the default table data instead of the table that the user selected. When I check this in the Network Response I can see after making the edit the server-side script runs twice, which it is supposed to happen to my understanding. The first script shows the DT_RowID is the data from the table that the user selected but when I make the inline edit the server-side script runs again but this time the DT_RowID has changed back to the default table and updated that table instead of the one the user selected. So is there a way to hold that DT_Row ID until the data has been submitted to the db? I am not familiar enough with the process of how the editor works to know where the issue is occurring. Any advice would help. Thanks
This question has an accepted answers - jump to answer
Answers
It sounds like the database variable might not be getting sent with the Editor Ajax request perhaps? Can you show me the code you are using please?
Thanks,
Allan
That is what it seems like as well. Here is my code for that.
And this is what I am doing on the server-side.
<?php > ?>```
<?php
include_once $_SERVER['DOCUMENT_ROOT'].'/dependencies/conn.php';
setlocale(LC_MONETARY, 'en_US.UTF-8');
if($_POST['val'] == ''){
$var_value = 'rfp_table';
}else{
$var_value = $_POST['val'].'_rfp_table';
}
$haz = "SELECT * FROM haz_miles";
$query2= mysqli_query($conn, $haz);
while($row2 = $query2->fetch_assoc()) {
$haz1 = $row2['haz1'];
$haz2 = $row2['haz2'];
$haz3 = $row2['haz3'];
$haz4 = $row2['haz4'];
}
mysqli_free_result($result2);
<?php
<?php > ``` ?>include( "../../../Editor-1.9.2/lib/DataTables.php" );
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;
Editor::inst( $db, $var_value )
->fields(
Field::inst( 'origin_city' ),
Field::inst( 'origin_state' ),
Field::inst( 'destination_city' ),
Field::inst( 'destination_state' ),
Field::inst( 'truck_type' ),
Field::inst( 'spot_num_companies' ),
Field::inst( 'spot_num_reports' ),
Field::inst( 'our_avg_lh' ),
Field::inst( 'our_num_reports' ),
Field::inst( 'ann_volume' ),
Field::inst( 'cust_miles' ),
Field::inst( 'market_avg_lh_dat' ),
Field::inst( 'dat_miles' ),
Field::inst( 'avg_rpm' ),
Field::inst( 'carrier_fuel' ),
Field::inst( 'cust_fuel' ),
Field::inst( 'percent_margin' ),
Field::inst( 'margin_flat' )
->setFormatter( function ( $val, $data, $opts ) {
return round($val, 2);
} ),
Field::inst( 'cust_flat' )
->setFormatter( function ( $val, $data, $opts ) {
return round($val, 2);
} ),
Field::inst( 'cust_all_in' )
->setFormatter( function ( $val, $data, $opts ) {
return round($val, 2);
} ),
Field::inst( 'carrier_flat' )
->setFormatter( function ( $val, $data, $opts ) {
return round($val, 2);
} ),
Field::inst( 'carrier_all_in' )
->setFormatter( function ( $val, $data, $opts ) {
return round($val, 2);
} ),
Field::inst( 'all_in_gp' )
->setFormatter( function ( $val, $data, $opts ) {
return round($val, 2);
} ),
Field::inst( 'gp_percent' )
->setFormatter( function ( $val, $data, $opts ) {
return round($val, 2);
} ),
Field::inst( 'spot_low' ),
Field::inst( 'spot_high' ),
Field::inst( 'std' ),
Field::inst( 'time' ),
Field::inst( 'hazmat' ),
Field::inst( 'lane_id' ),
Field::inst( 'extra1' ),
Field::inst( 'extra2' ),
Field::inst( 'extra3' ),
Field::inst( 'extra4' ),
Field::inst( 'haz1' )->set( Field::SET_CREATE )
)
Could you put the
line inside the
data
function (for both Editor and DataTables) please? At the moment it is only being evaluated once - when the page is loaded. If it can change, it won't have any effect on the submitted data.Allan
Wow, I can't believe I missed that. It is working now. I actually have it like that on another table where I am using that function. Thank you so much for your help.