Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Cheryl! Tisland on Nov 02, 2009 08:38
open dhtmlx forum
Grid Postgres data connector

I am having a tough time with sending data over to my postgres database. Some of the values are coming in correctly, but some are not.

grid setup looks like this:

    mygrid = new dhtmlXGridObject('mygrid_container');
    mygrid.setImagePath('javascript/dhtmlxGrid/codebase/imgs/');
    mygrid.setHeader("Line, Product Id, Product, Qty, On Hand, UOM, Price, Discount %, Ext Price,TP,Haz/Res, Date Req'd, Reserved, Delivered, Invoiced, Returned, Description, Haz Mat Handling, Restrictions,Weight, avgcost,taxamount");
    mygrid.setColumnIds("line_no,m_product_id,product_name,quantity, onhand,uom, price,discount,extprice,tp,hazres, datereqd, reserved, delivered, invoiced, returned,description, hazmathandling,restrictions,weight,avgcost,taxamount");
    //mygrid.attachHeader("#connector_text_filter,#connector_text_filter")
    mygrid.setInitWidths("50,0,180,40,50,100,70,70,70,50,70,90,70,70,70,70,100,100,100,0,0,0");
    mygrid.setColTypes("cntr,ed,ed,ed,ro,combo,ron,ed,ron,ed,ro,dhxCalendar,ro,ro,ro,ro,ro,txt,ro,ro,ro,ro");
    mygrid.setColSorting("connector,connector")
    //mygrid.setColumnVisibility("false,true,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,true");
    //mygrid.enableSmartRendering(true)
    mygrid.enableMultiselect(true);
    mygrid.submitOnlyChanged(false);
    mygrid.setSkin("light");
    mygrid.setNumberFormat("0,000.00", 6,".",",");
    mygrid.setNumberFormat("0,000.00", 8,".",",");
    mygrid.enableEditEvents(1,1,1);
    //mygrid.setDateFormat("%m/%d/%Y");
    mygrid.attachEvent("onEditCell", doGetProduct);
    mygrid.attachEvent("onRowSelect",doOnRowSelected);
    mygrid.init();
    uomCombo = mygrid.getColumnCombo(5);
    uomCombo.readonly(true);
//uomCombo.enableFilteringMode(true);
    
uomCombo.loadXML("functions/buildCombos.php?comboType=c_uom&orgfilter=false");

        mygrid.loadXML("php/product_row_connector.php?salesorderno="+document.getElementById('salesorderno').value);
    
        //var dp = new dataProcessor("php/product_row_connector.php?salesorderno="+document.getElementById('salesorderno').value);
        var dp = new dataProcessor("php/product_row_connector.php?salesorderno="+document.getElementById('salesorderno').value);
        dp.setVerificator(1,checkRowForInsert);
        //dp.setTransactionMode("GET",true);
        //dp.setUpdateMode("row");
        //dp.enableDataNames(true);
        //dp.enableDebug(true);
        dp.init(mygrid);


product_row_connector.php looks like this:

    require_once("../config.php");
    $res=pg_connect($postrgre_connection);

    require("../javascript/dhtmlxConnector/codebase/grid_connector.php");
    require("../javascript/dhtmlxConnector/codebase/db_postgre.php");
    
    $salesorderno=$_GET['salesorderno'];
    $grid = new GridConnector($res,"Postgre");
    $grid->enable_log("temp.log",true);
    $grid->dynamic_loading(100);


    //$grid->event->attach("beforeInsert","productInsert");



    //$grid->render_table("pos_line_data","pos_line_data_id","line_no,m_product_id,product_name,quantity");

    $grid->sql->attach("Update","update pos_line_data set line_no='{line_no}', m_product_id='{m_product_id}', product_name='{product_name}', quantity='{quantity}', on_hand='{on_hand'},uom='{uom}', price='{price}', discount_price='{discount_price}', ext_price='{ext_price}', sales_order_no='{$salesorderno}',tp='{tp}',hazres='{hazres}' where pos_line_data_id='{pos_line_data_id}'");
    $grid->sql->attach("Insert","insert into pos_line_data (pos_line_data_id, line_no, m_product_id,product_name,quantity,on_hand,uom,price,discount_price,ext_price, sales_order_no,tp,hazres) values('{pos_line_data_id}','{line_no}', '{m_product_id}','{product_name}','{quantity}','{onhand}','{uom}','{price}','{discount_price}','{ext_price}','{$salesorderno}','{tp}','{hazres}') ");
    $grid->render_sql("select pos_line_data_id, line_no, m_product_id, product_name, quantity, uom, price, discount_price, ext_price,tp,hazres from pos_line_data where sales_order_no={$salesorderno}", "pos_line_data_id", "line_no,m_product_id,product_name,quantity,uom,price,discount_price,ext_price");



However, when my database table gets updated. Some of the values are in the wrong column and the onhand, tp and hazres show up as {onhand}, {tp}, {hazres} instead of their values from the grid. The other fields come across as values just fine but some go into the wrong columns in the db.

What am I doing wrong?

Thank you
Answer posted by Stanislav (support) on Nov 03, 2009 06:02
Please beware that mygrid.setColumnIds will not affect the names in server side scripts. 
The connector uses the same list of columns names as was used in render_table,  render_sql command ( the first element of list will be used as name for data from first columns and so for )