Refresh grid after insertion of a record.

QuestionsRefresh grid after insertion of a record.
Montemaggiore Sebastian asked 9 years ago

Hello. I have another question. How do i in order to automatically refresh the grid after i insert a new record?. Thanks.

10 Answers
Abu Ghufran answered 9 years ago

Hi,

By default, It do (ajax) refresh the grid in which record is added.
If you want to refresh the whole page, then add …

$grid["add_options"]["afterSubmit"] = "function(){jQuery('#list1').trigger('reloadGrid',[{page:1}]); return [true, ''];}";
$g->set_options($grid);

Given that list1 is grid id.

Montemaggiore Sebastian answered 9 years ago

Hi. I doesn´t work. What i want is to refresh the whole page. In a point i use,

$grid["scroll"] = true;

so the "program counter" it doesn´t have to return to the first page.

I really appreciate your help. Thanks.

Part of my code is,

// Creo el grid con el que voy a trabajar.
$g = new jqgrid();

// Al grid le doy un nombre.
$grid["caption"] = "Listado de pedidos";
$grid["multiselect"] = true;
$grid["autoresize"] = true;
$grid["sortorder"] = "DESC";
$grid["add_options"] = array('width'=>'420');
$grid["edit_options"] = array('width'=>'420');
$grid["view_options"] = array('width'=>'420');
$grid["height"] = "500";
$grid["loadtext"] = "Cargando …";
$grid["scroll"] = true;
$grid["actionicon"] = true;
//$grid["reloadedit"] = true;
//$grid["edit_options"]["reloadAfterSubmit"]=false;
$grid["add_options"]["afterSubmit"] = "function(){jQuery('#listado_de_pedidos').trigger('reloadGrid'); return [true, ''];}";
$g->set_options($grid);

$e["on_update"] = array("update_row", null, true);

$e["on_insert"] = array("insert_row", null, true);

$g->set_events($e);

function update_row($data)
{
$str = "SELECT * FROM pedidos WHERE id = {$data["id"]}";
$resultado = mysql_query($str);
$nro_registros = mysql_num_rows($resultado);
if ( $nro_registros == 0)
phpgrid_error('Este registro ha sido eliminado por otro usuario, por favor refresque la página (tecla F5).');
else {
$rs = mysql_fetch_assoc($resultado);
if ( strtotime($rs["ultima_modificacion"]) > strtotime($data["params"]["ultima_modificacion"]) )
phpgrid_error('Este registro ha sido modificado por otro usuario, por favor refresque la página (tecla F5).');
}

// update new timestamp
$data["params"]["ultima_modificacion"] = date("Y-m-d H:i:s");

}

function insert_row($data)
{
if ($data["params"]["es_tarea_predefinida"] == "Si")
{
mysql_free_result($str);
$str = "SELECT * FROM tareas_predefinidas";
$resultado = mysql_query($str);
$nro_registros = mysql_num_rows($resultado);
if ($nro_registros < 20)
{
$str = "INSERT INTO tareas_predefinidas SET
tarea_predefinida = '".$data["params"]["observaciones"]."',
estampilla_tiempo = '".date("Y-m-d H:i:s")."'";
//phpgrid_error($str);
$resultado = mysql_query($str);
}
else // La cantidad de registros es igual a 20
{
// Borro la tarea predefinida con la estampilla de tiempo mas vieja.
$str = "DELETE * FROM tareas_predefinidas WHERE estampilla_tiempo = (SELECT min(estampilla_tiempo) FROM tareas_predefinidas)";
$resultado = mysql_query($str);

$str = "INSERT INTO tareas_predefinidas SET
tarea_predefinida = '".$data["params"]["observaciones"]."',
estampilla_tiempo = '".date("Y-m-d H:i:s")."'";
$resultado = mysql_query($str);
};
};
}

// Le indico al grid a que tabla de la base de datos va a estar unido; es decir, de donde salen los registros que va a mostrar.
$g->table = "pedidos";

Abu Ghufran answered 9 years ago

My mistake, it should be … window.location.reload();

$grid["add_options"]["afterSubmit"] = "function(){ window.location.reload(); return [true, ''];}";
$g->set_options($grid);

Montemaggiore Sebastian answered 9 years ago

Thanks!!. It works!!.

Abu Ghufran answered 9 years ago

Yes, thats correct.

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

Montemaggiore Sebastian answered 9 years ago

Hello.If i want to refresh the whole page after editing a grid, si correct to use the word "edit"instead of "add"?

$grid["edit_options"]["afterSubmit"] = "function(){ window.location.reload(); return [true, ''];}";
$g->set_options($grid);

Thanks.

rezky answered 9 years ago

I doesn´t work, please help me I use CI

Abu Ghufran answered 9 years ago

If using dialog editing mode,

$grid["edit_options"]["afterSubmit"] = "function(){ window.location.reload(); return [true, ''];}";
$g->set_options($grid);

If using inline edit mode,

$grid["onAfterSave"] = "function(){ window.location.reload(); }";
$g->set_options($grid);

rezky answered 9 years ago

Hi Abu

Still doesn't work

this my code

$g = new jqgrid();
//$grid["scroll"] = true;
$grid["rowNum"] = 20; // by default 20
$grid["sortname"] = 'kode_suplier'; // by default sort grid by this field
$grid["sortorder"] = "DESC"; // ASC or DESC
$grid["autowidth"] = true; // expand grid to screen width
$grid["multiselect"] = true; // allow you to multi-select through checkboxes
$grid["rowactions"] = true; // allow you to multi-select through checkboxes
$grid["form"]["position"] = "center";
$grid["loadtext"] = "Mohon Tunggu …";
$grid["export"] = array("format"=>"xls", "filename"=>"data-Trending Topic", "sheetname"=>"List Supplier");
$$grid["add_options"]["afterSubmit"] = "function(){ window.location.reload(); return [true, ''];}";
$g->set_options($grid);

$g->set_actions(array(
"add"=>true,
"edit"=>true,
"delete"=>true,
"rowactions"=>true,
"export"=>true,
"autofilter" => true,
"search" => "advance"
)
);

$g->select_command = "SELECT * FROM tb_supplier";

$g->table = "tb_supplier";

$col = array();
$col["title"] = "Kode ";
$col["name"] = "kode_suplier";
$col["width"] = "180";
$col["search"] = true;
$col["editable"] = true; // this column is editable
$col["editoptions"] = array("size"=>3,"maxlength"=>3);
// with default display of textbox with size 20
$col["editrules"] = array("required"=>true, "edithidden"=>true,"readonly"=>true); // and is required

$cols[] = $col;

$col = array();
$col["title"] = "Nama Supplier ";
$col["name"] = "nama_suplier";
$col["width"] = "180";
$col["search"] = true;
$col["editable"] = true;
$cols[] = $col;

$col = array();
$col["title"] = "ALamat";
$col["name"] = "alamat_suplier";
$col["width"] = "180";
$col["search"] = true;
$col["editable"] = true;
$cols[] = $col;

$col = array();
$col["title"] = "Kontak";
$col["name"] = "kontak_suplier";
$col["width"] = "180";
$col["search"] = true;
$col["editable"] = true;
$cols[] = $col;

$col = array();
$col["title"] = "Tlp";
$col["name"] = "telp_suplier";
$col["width"] = "180";
$col["search"] = true;
$col["editable"] = true;
$cols[] = $col;

$col = array();
$col["title"] = "Action";
$col["name"] = "act";
$col["width"] = "90";
$cols[] = $col;

$g->set_columns($cols);

$out = $g->render("list1");

$data['out'] = $out;
$data['outgrid'] = 'grids';

$data['lebel'] = 'SUPPLIER';
$data['main_content'] = 'supplier';
$this->load->view('include/template', $data);

Abu Ghufran answered 9 years ago

I don't see edit_options in your code.
Second, there seems to be a typo $$

$$grid["add_options"]["afterSubmit"] …

It would be easier if you email me php flle at [email protected]

Your Answer

20 + 0 =

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?