Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Florian Banowski on Jul 09, 2009 02:35
open dhtmlx forum
New Row in Grid and Database

Hi there,

now, i have a new problem.

I want to add a row by pressing enter or tab or click on the normal addRow- Button in my grid.

In this row i want to focus automaticly the second "ed" field, when the field is != '' then it should add it in my database, read the new id out and add a new row.

If the user dont add any entrys in the "ed" then should it be ignored.

this is my source htm file:
<div id="gridbox" style="width:auto;height:500px;"></div>
<script>
    mygrid = new dhtmlXGridObject('gridbox');
    mygrid.setImagePath("opt/dhtmlx_grid/imgs/");
    mygrid.setSkin("light");
    //mygrid.setDateFormat("%d.%m.%Y - %H:%i");

    mygrid.setHeader("ID,Benutzername,E-Mail,Date,Sitzung,Login,#cspan,#cspan");
    mygrid.attachHeader("#rspan,#connector_text_filter,#connector_text_filter,#rspan,#rspan,Status,Error,Fatal Error")
    //mygrid.setSizes();
    mygrid.enableTooltips("false,false,false,false,false,false,false,false");
    
    mygrid.setInitWidths("60,*,*,*,*,*,*,*");
    mygrid.setColTypes("ro,ed,ro,ed,ro,ch,ch,ch");
    mygrid.setColAlign("center,left,left,left,left,center,center,center");
    mygrid.setColSorting("connector,connector,connector,connector,connector,connector,connector,connector");
    
    mygrid.enableEditEvents(false,false,true);
    
    mygrid.enableSmartRendering(true);
    //mygrid.enableAutoHeigth(true,"400");
    mygrid.enableMultiselect(true)
    
    mygrid.init();
    
    mygrid.loadXML("usr/bin/grid/ecm/user/list.php");
    
    var myDataProcessor = new dataProcessor("usr/bin/grid/ecm/user/list.php");
    //myDataProcessor.setUpdateMode("off");
    myDataProcessor.init(mygrid);

    mygrid.attachEvent("onRowDblClicked",onRowDblClicked);
    
    function onRowDblClicked(rowId,cellInd) {
        WindowOpen("?module=erp&index=merchandise&action=show_article&id="+rowId, "Product",1);    
    }
    
    mygrid.addRow(124,"auto_id","","","","","","","");
</script>

and this is my source php file
<?php
    require_once("../../../../../etc/mysql.php");
    $res=mysql_connect(DAB_HOST,DAB_USER,DAB_PASS);
    mysql_select_db(DAB_DBAS);

    require("../../../../../opt/dhtmlx_connector/grid_connector.php");
    $grid = new GridConnector($res);
    #$grid->enable_log("temp.log",true);
    $grid->dynamic_loading(50);
    #$grid->render_table("crm_data","id","id,company,street,zipcode,city,email,phone,fax");
    $grid->render_sql("SELECT * FROM user WHERE status=0 OR status=1", "id","id,name,email,date,session,status,login_error,login_error_fatal");
?>

I'll hope you can help.

Sry, for my english.

Best regards
Florian Banowski
Answer posted by dhxSupport on Jul 09, 2009 03:28
>>I want to add a row by pressing enter or tab or click on the normal addRow- Button in my grid.
You can use "onEnter" or "onTab" events to call addRow() method. 
>>In this row i want to focus automaticly the second "ed" field
You can switch necessary cell to the edit mode using editCell() method. 
Please check this article http://www.dhtmlx.com/docs/products/kb/index.shtml?cat=search&page=1&q=10062&ssr=yes&s=editCell
>>when the field is != '' then it should add it in my database, read the new id out and add a new row.
You can set dataProcessor's auto update mode off and send data to the server side after user entered value to the cell:
mygrid.attachevent("onEditCell",function(stage,rowId,cellInd,nValue,oValue){
if (stage==2&&cellInd==1&&nValue!=""){
dp.sendData();
return true;
}
return true;
})

Or you can use DataProcessor inbuild validation. Please find more information here http://dhtmlx.com/docs/products/dhtmlxGrid/doc/articles/Dataprocesor_usage.html#grid_art_dataprocessor
Answer posted on Jul 15, 2009 16:20

Hi, now i have written a function, which should add a row, and select the 2nd ed field automaticly. It runs good, but when i update my datagrid with clearAll and loadXML at the function onAfterUpdateFinish it only adds a row and dosent show the new content and it dosent select automaticly the 2nd field.

What can i do to comeoff?

Here's the code-selection:

 function newRow()
 { 
  var id=mygrid.uid();
  mygrid.addRow(id,'',0);
  mygrid.showRow(id);
  //(arguments[0]||window.event).cancelBubble=true;
  mygrid.selectCell(0,1,true,false,true);
 }

 function onEditCell (stage,rowId,cellInd,nValue,oValue)
 {
  if (stage==2&&cellInd==1&&nValue!=""){
   myDataProcessor.sendData();
  } 
 }

 function onAfterUpdateFinish (stage,rowId,cellInd,nValue,oValue)
 {
  mygrid.clearAll();
  mygrid.loadXML("list.php?id={ID}");
  //window.location.reload(true);
  newRow();
 }

Best regards
Florian Banowski

Answer posted by dhxSupport on Jul 16, 2009 02:01
 mygrid.loadXML("list.php?id={ID}"); method works in asynchronous mode. newRow() function called event if not all rows was loaded to the grid. You should wait till all rows was loaded in the grid:
 mygrid.loadXML("list.php?id={ID}",function(){
  newRow();
});