After filter, editing lost primary key

Talk about Filter (search) Settings

Moderator: alexandrleonenko

afullana
Newbie
Newbie
Posts: 8
Joined: Jan 27th, '11, 13:35

After filter, editing lost primary key

Postby afullana » Aug 17th, '11, 07:41

Hello,

I have a problem when editing records from a search result. Without any applied filter works perfectly well as a link to edit the "linktoedit." but
when applying a filter to edit the link does not include the id of the record, "linktoedit" if it works well. And by clicking on the "linktoedit" edit screen does not show log data.
SinFiltro.PNG
SinFiltro.PNG (16.51 KiB) Viewed 2917 times

ConFiltro.PNG
ConFiltro.PNG (43.1 KiB) Viewed 2913 times

By activating the debugger shows the select does not include the primary key.
Edit.PNG
Edit.PNG (52.48 KiB) Viewed 2913 times

I have reviewed the post:
http://www.apphp.net/forum/viewtopic.php?f=11&t=2359
http://www.apphp.net/forum/viewtopic.php?f=20&t=2383
and the solution does not work

Any idea? TIA

additional info:
PHP DataGrid Pro (AJAX enabled) version 6.4.1
Database: mysql
OS Server: CentOS release 5.3 (Final)

PS: sorry for my english
Last edited by afullana on Aug 17th, '11, 07:55, edited 1 time in total.

administrator
Site Admin
Site Admin
Posts: 5997
Joined: Jan 7th, '09, 23:18
Contact:

Re: After filter, editing lost primary key

Postby administrator » Aug 17th, '11, 07:51

1. What version do you work with?
2. Look here: http://www.apphp.com/php-datagrid/examp ... 1_demo.php
Does it make the same problem, when you click on Edit link?

afullana
Newbie
Newbie
Posts: 8
Joined: Jan 27th, '11, 13:35

Re: After filter, editing lost primary key

Postby afullana » Aug 17th, '11, 08:02

1. PHP DataGrid Pro (AJAX enabled) version 6.4.1
2. the example works fine, my problem is the lost of the primary key in the link to "edit", the link is "javascript:f__doPostBack("edit", "-1","") (for all the records) but the correct link is "javascript:f__doPostBack("edit", "144")

Thanks for your fast respone

administrator
Site Admin
Site Admin
Posts: 5997
Joined: Jan 7th, '09, 23:18
Contact:

Re: After filter, editing lost primary key

Postby administrator » Aug 18th, '11, 08:14

1. Did you properly define table for Edit Mode?
2. Try to run v6.7.5
Do you get the same error?

afullana
Newbie
Newbie
Posts: 8
Joined: Jan 27th, '11, 13:35

Re: After filter, editing lost primary key

Postby afullana » Aug 19th, '11, 09:00

Hi,

in version 6.7.5 i have the same problem,

the definition for the edit section is:

Code: Select all

    ## +---------------------------------------------------------------------------+
    ## | 7. Add/Edit/Details Mode Settings:                                        |
    ## +---------------------------------------------------------------------------+
    $em_table_properties = array("width"=>"70%");
    $dgrid->SetEditModeTableProperties($em_table_properties);
    $dm_table_properties = array("width"=>"70%");
    $dgrid->SetDetailsModeTableProperties($dm_table_properties);
   $table_name  = "eoc_asignacionmovil";
   $primary_key = "asignacionmovilid";
   $condition   = "";
   $dgrid->SetTableEdit($table_name, $primary_key, $condition);
    $fill_from_array = array("10000"=>"10000", "250000"=>"250000", "5000000"=>"5000000", "25000000"=>"25000000", "100000000"=>"100000000");
    $em_columns = array(
      "telefono"         =>array("header"=>"Telefono",    "type"=>"textbox", "req_type"=>"rt"),
      "extension"        =>array("header"=>"Extension",   "type"=>"textbox", "req_type"=>"rt"),
      "multisin"         =>array("header"=>"Multisin",    "type"=>"enum",    "req_type"=>"rt", source=>$sino_array),
      "tdual"            =>array("header"=>"Dual",        "type"=>"enum",    "req_type"=>"rt", source=>$sino_array),
      "umts"             =>array("header"=>"UMTS",        "type"=>"enum",    "req_type"=>"rt", source=>$sino_array),
      "ipad"             =>array("header"=>"Ipad",        "type"=>"enum",    "req_type"=>"rt", source=>$sino_array),
      "serviciobb"       =>array("header"=>"Servicio BB", "type"=>"enum",    "req_type"=>"rt", source=>$sino_array),
      "sim"              =>array("header"=>"SIM",         "type"=>"textbox", "req_type"=>"st"),
      "peticionalta"     =>array("header"=>"Codigo alta", "type"=>"textbox", "req_type"=>"st"),
      "alta"             =>array("header"=>"F alta",      "type"=>"date",    "req_type"=>"rt", "width"=>"80px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "calendar_type"=>"floating"),
      "peticionbaja"     =>array("header"=>"Codigo baja", "type"=>"textbox", "req_type"=>"st"),
      "baja"             =>array("header"=>"F baja",      "type"=>"date",    "req_type"=>"st", "width"=>"80px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "calendar_type"=>"floating")
      );
      $dgrid->SetColumnsInEditMode($em_columns);
   $dgrid->SetForeignKeysEdit($foreign_keys);

lambro
Master
Master
Posts: 102
Joined: Sep 13th, '10, 14:31
Location: Metz, France

Re: After filter, editing lost primary key

Postby lambro » Aug 19th, '11, 09:42

Hi ! Apparently, your id-field name disappears from the sql query generated by the search field.
It might be related to the @SetRealEscapeStringByDbType() function.
See this thread here for further information.
You might wanna check if the field still disappears when, in your datagrid class.php, you comment out this peculiar function.

But prior to that, you have to put your id_field in the $em_columns array, at first place. You have to, because the dg will use it to access each and every row of the sql result.
If you do not want it to be displayed, use the "visibile"=>false option.

afullana
Newbie
Newbie
Posts: 8
Joined: Jan 27th, '11, 13:35

Re: After filter, editing lost primary key

Postby afullana » Sep 14th, '11, 14:49

HI,

yes the problem is id-field name disappears from the sql.

If you comment the function:

Code: Select all

     / **
      * Set DB real escape string by type
      * /
     protected function SetRealEscapeStringByDbType ($ field_value = "") {
     / / If ($ this-> allowRealEscape) return $ field_value;
     / / Switch ($ this-> dbHandle-> phptype) {
     / / Case "mysql": / / mysql
     / / Return @ mysql_real_escape_string ($ field_value) break;
     / / Case "pgsql": / / PostgreSQL
     / / Return @ pg_escape_string ($ field_value) break;
     / / Default:
                 return $ field_value;
     / /}
     }
the result is the same

the order of function calls obj_start () and $ your_dgrid-> Bind () is as follows:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <title>Telefon&iacute;a movil. Mantenimiento de moviles</title>
    <meta http-equiv=Content-Type content="text/html; charset=utf-8">
</head>
<body>

<?php
   ################################################################################
   ################################################################################
   ## +---------------------------------------------------------------------------+
   ## | 1. Creating & Calling:                                                    |
   ## +---------------------------------------------------------------------------+
   define ("DATAGRID_DIR", "");
   define ("PEAR_DIR", "pear/");
   require_once(DATAGRID_DIR.'datagrid.class.php');
   require_once(PEAR_DIR.'PEAR.php');
   require_once(PEAR_DIR.'DB.php');

    ##  *** creating variables that we need for database connection
   $DB_USER='xxxxxxxx';
   $DB_PASS='xxxxxxxxx';
   $DB_HOST='xxxxxxxxxx';
   $DB_NAME='eoc_prd';
   $db_conn = DB::factory('mysql');  /* dont forget to change on appropriate db type */
   $result_conn = $db_conn->connect(DB::parseDSN('mysql://'.$DB_USER.':'.$DB_PASS.'@'.$DB_HOST.'/'.$DB_NAME));
   if(DB::isError($result_conn)){ die($result_conn->getDebugInfo()); }
    ##  *** put a primary key on the first place
   $sql="select asignacionmovilid "
      .", telefono "
      .", extension "
      .", multisin "
      .", serviciobb "
      .", tdual "
      .", asignadotexto "
      .", umts "
      .", ipad "
      .", eoc_asignacionmovil.alta "
      .", eoc_asignacionmovil.baja "
      .", peticionalta "
      .", peticionbaja "
      .", sim "
      .", eoc_gestor.nombreempleado gestor "
      ."from eoc_asignacionmovil "
      ."left join eoc_listado_nombreempleado eoc_gestor on (eoc_gestor.empleado_id = eoc_asignacionmovil.gestorid) ";
    ##  *** set needed options and create a new class instance
   $debug_mode = false;        /* display SQL statements while processing */
   $messaging = true;          /* display system messages on a screen */
   $unique_prefix = "f_";    /* prevent overlays - must be started with a letter */
   $dgrid = new DataGrid($debug_mode, $messaging, $unique_prefix, DATAGRID_DIR);
    ##  *** set data source with needed options
   $default_order_field = "telefono";
   $default_order_type = "ASC";
   $dgrid->DataSource($db_conn, $sql, $default_order_field, $default_order_type);
   $sino_array = array("0"=>"No", "1"=>"Si", "2"=>"Sin definir");
   ob_start();
    ## +---------------------------------------------------------------------------+
    ## | 2. General Settings:                                                      |
    ## +---------------------------------------------------------------------------+

...

    ################################################################################
    ## +---------------------------------------------------------------------------+
    ## | 8. Bind the DataGrid:                                                     |
    ## +---------------------------------------------------------------------------+
    ##  *** bind the DataGrid and draw it on the screen
    $dgrid->Bind();
    ob_end_flush();
    ################################################################################
?>
</body>
</html>


I've also added the primary key to the array em_columns, and the problem persist
PS: I have delayed in responding because I was on vacation,

administrator
Site Admin
Site Admin
Posts: 5997
Joined: Jan 7th, '09, 23:18
Contact:

Re: After filter, editing lost primary key

Postby administrator » Sep 15th, '11, 07:55

Please send us a full example of your code or uploaded the demo on any shared server with debug option turned On, so we could understand what happens.

afullana
Newbie
Newbie
Posts: 8
Joined: Jan 27th, '11, 13:35

Re: After filter, editing lost primary key

Postby afullana » Sep 15th, '11, 08:04

hi,

Here is the file with the code

thanks for your colaboration
Attachments
eoc_asignacionmovil3.zip
(3.55 KiB) Downloaded 144 times

administrator
Site Admin
Site Admin
Posts: 5997
Joined: Jan 7th, '09, 23:18
Contact:

Re: After filter, editing lost primary key

Postby administrator » Sep 15th, '11, 08:08

We've checked and it worked fine for us.
Please wait for the next version, that is planned to release in few weeks, hope it will help you.


Return to “Settings: Filtering (search) / Autocomplete”