function dadabik_change_status: no jump to top

Hello,

I have create a custom button and switch the status of my data with this code, where documented in the capitel "6.10. Custom buttons"

[pre]
function dadabik_change_status($table_name, $where_field, $where_value)
{
global $conn, $dadabik_main_file, $quote;
$sql = "UPDATE orders set status_order_user = 'approved' WHERE ".$quote.$where_field.$quote." = :where_value";
$res_prepare = prepare_db($conn, $sql);
$values_to_bind = array();
$values_to_bind['where_value'] = $where_value;

foreach ($values_to_bind as $key => $value)
{
$res_bind = bind_param_db($res_prepare, ':'.$key, $value);
}

$res = execute_prepared_db($res_prepare,0);

// let's go back to the results grid
header('Location:'.$dadabik_main_file.'?function=search&tablename='.urlencode($table_name));
exit;
}
[/pre]

This code works fine, but if I click to the button and then he refreshed data grid page, he jump to top of the page.
So if I have to change the status from multible lines e.g. row# 100, I must after every line scroll to the line 100+ and click the next button from the next line.
Can you tell me, how can I set the code, that he not jump to top of the page?

Regards
Michael
 

eugenio

Administrator
Staff member
Hello,
if you load $dadabik_main_file.'?function=search&tablename='.urlencode($table_name), the browser will load the page and move to the top, the only way to make it move it to a specific record is by adding an anchor, such as #111 where #111 is the anchor of the record you want to move to. But you would need to add this anchor, automatically, in a field, when you insert the record.

The other option you have is to use a php_ajax button instead of a php_standard one; the problem you might have here is the following: if the field you want to modify with the button is visible in the grid, you won't see it updated until the page is loaded again.

Best,
 
I was wondering about this too.
When you go to a detail page, the browser "Back" button takes you back to the position in the grid you came from, but the DaDaBIK "Go back" button goes back to the top of the grid.
If DaDaBIK auto-generated an anchor for each grid using some sort of hash of the primary key, then the Go Back would be much more useful, especially on long result grids.
Alternatively, is it possible for us to add our own anchors using a custom datagrid template and a custom hashing function, which could also be invoked from a custom "Go Back" button ?
 

eugenio

Administrator
Staff member
Very interesting, I will evaluate it, I think the implementation is not difficult and can help both in the back button and in the results grid button situations.

About the anchor, yes I think you can already produce it using a "fake" field that, after insert and update, is updated (using hooks) with the value of the primary key of the record ... then with a custom formatting function you can produce the anchor. You can't change the link of the standard "back" button, though ... so it might be useful only in the scenario explained by Michael.

Best,
 
Top