Refresh the grid after update

QuestionsRefresh the grid after update
Gerd asked 8 years ago

Hallo,

i have defined two buttons in the grid to set or unset a field in the grid. My problem is, that after the update the grid is not refreshed. I want to have the refresh automatically after the update.

here is my code:

$opt["add_options"]["afterSubmit"] = "function(){ window.location.reload(); return [true, ''];}";
$opt["bulkedit_options"]["afterShowForm"] = "function(){ }";

function update_data($data)
{
// temp grid object to execute sql
$g = new jqgrid();

// If bulk operation is requested, (default otherwise)
if ($data["params"]["bulk"] == "set-desc")
{
$selected_ids = $data["id"]; // e.g. the selected values from grid 5,7,14 (where "id" is field name of first col)
$str = $data["params"]["data"];

// here you can code your logic to do bulk processing
$g->execute_query("UPDATE invheader SET note = '$str' WHERE id IN ($selected_ids)");

// first param is message, second is autofade after 1 sec (0/1)
phpgrid_msg("Custom Message: Download zip file from <a target='_blank' href='http://google.com'>http://google.com</a>&quot;,0);
die;
}
else if ($data["params"]["bulk"] == "send-email")
{
$selected_ids = $data["id"]; // e.g. the selected values from grid 5,7,14 (where "id" is field name of first col)
// sending email logic

$g->execute_query("UPDATE invheader SET note = 'Email Sent' WHERE id IN ($selected_ids)");
die;
}
else if ($data["params"]["bulk"] == "add-voting")
{
$selected_ids = $data["id"]; // e.g. the selected values from grid 5,7,14 (where "id" is field name of first col)
$array_id = explode(",",$selected_ids);

// alle Einträge in Tabelle hhc_voting_titel_auswahl löschen
// Auswahl aus GRID in Tabelle hhc_voting_titel_auswahl einfügen

#$g->execute_query("DELETE from hhc_voting_titel_auswahl WHERE hhc_voting_titel_auswahl.fk_hhc_voting_id_voting=".$_GET['id_voting']."");

foreach ($array_id as $value)
{
$query = "INSERT INTO hhc_voting_titel_auswahl
(
fk_hhc_voting_id_voting
, fk_hhc_titel_id_titel
, dt_auswahl_titel
, dt_geaendert_am
, fk_geaendert_durch
, dt_angelegt_am
, fk_angelegt_durch
)
VALUES ('".$_GET['id_voting']."',
'".$value."',
'1',
"."current_timestamp,".
$_SESSION['sys_userid'].",
"."current_timestamp,".
$_SESSION['sys_userid'].")";
$g->execute_query($query);
}

$str = $data["params"]["data"];
#$g->execute_query("UPDATE invheader SET total = '$str'");
die;
}
else if ($data["params"]["bulk"] == "del-voting")
{
$selected_ids = $data["id"]; // e.g. the selected values from grid 5,7,14 (where "id" is field name of first col)
$array_id = explode(",",$selected_ids);

// alle Einträge in Tabelle hhc_voting_titel_auswahl löschen
// Auswahl aus GRID in Tabelle hhc_voting_titel_auswahl einfügen

foreach ($array_id as $value)
{
$query = "DELETE from hhc_voting_titel_auswahl WHERE hhc_voting_titel_auswahl.fk_hhc_voting_id_voting=".$_GET['id_voting']
." and fk_hhc_titel_id_titel =".$value ;
$g->execute_query($query);
}

$str = $data["params"]["data"];
#$g->execute_query("UPDATE invheader SET total = '$str'");
die;
}
}

5 Answers
Abu Ghufran answered 8 years ago

Hi,

By default the grid do refresh after each add/update operation.
If it is not doing it, please check for some JS error in browser debug console (F12).

+ In your code, following lines are just for demo purpose.

// If bulk operation is requested, (default otherwise)
if ($data["params"]["bulk"] == "set-desc")
{
$selected_ids = $data["id"]; // e.g. the selected values from grid 5,7,14 (where "id" is field …..
…..
…..
$g->execute_query("UPDATE invheader SET note = 'Email Sent' WHERE id IN ($selected_ids)");
die;
}

Gerd answered 8 years ago

Hallo Abu,

i have send you an email with the whole php-file and a description what i want to do to [email protected] . Did you get it ?

Gerd

Abu Ghufran answered 8 years ago

Yes, i am reviewing it. I'll be updating you on email.

Gerd answered 8 years ago

Hallo Abu,

thank you for your help.

I have uploaded my scripts to the provider and there it works fine.

I have you send the link inan email, please have a look.

My Test environment is:
– xampp
– PhpED from Nusphere 17.x
– Windows 10

have you any idee, why it doesn't work in my Test ?

Can i change the message after Update?

Regards,

Gerd

Abu Ghufran answered 8 years ago

Hi,

I tested bulk-edit auto-reload on xampp and unable to genereate this issue.
It auto-refresh grid on update.

One more test: try commenting header('content-type: text/html; charset=utf-8');

Your Answer

12 + 10 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?