jQuery UI Widgets › Forums › Grid › Issue with combobox column when adding a new row

This topic contains 5 replies, has 2 voices, and was last updated by  Hristo 9 years, 4 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author

  • Abdo
    Participant

    I have an editable grid that include a combobox column. On rowupdate I need to store the rowdata in a js buffer so i can flush it later to php server side. I am using the source “updaterow” event to capture the changes and save them in the in the buffer under rowid (or rowdata.uid) key.

    Everything is working fine except for the addrow event.
    When a new row is added to the grid using $(“#jqxgrid”).jqxGrid(“addrow”, null, {}, “first”), if I edit an input column the updaterow works fine but if I edit a combobox, the updaterow event always returns 0 as rowid and rowdata.uid so i can’t update my buffer properly

    Here is a simple case to demonstrate the issue (code based on cascadingediting,html example):

    <!DOCTYPE html>
    <html lang=”en”>
    <head>
    <title id=’Description’>This example shows how to implement cascading comboboxes in
    jqxGrid.</title>
    <link rel=”stylesheet” href=”../../jqwidgets/styles/jqx.base.css” type=”text/css” />
    <script type=”text/javascript” src=”../../scripts/jquery-1.11.1.min.js”></script>
    <script type=”text/javascript” src=”../../jqwidgets/jqxcore.js”></script>
    <script type=”text/javascript” src=”../../jqwidgets/jqxdata.js”></script>
    <script type=”text/javascript” src=”../../jqwidgets/jqxbuttons.js”></script>
    <script type=”text/javascript” src=”../../jqwidgets/jqxscrollbar.js”></script>
    <script type=”text/javascript” src=”../../jqwidgets/jqxmenu.js”></script>
    <script type=”text/javascript” src=”../../jqwidgets/jqxgrid.js”></script>
    <script type=”text/javascript” src=”../../jqwidgets/jqxgrid.selection.js”></script>
    <script type=”text/javascript” src=”../../jqwidgets/jqxgrid.pager.js”></script>
    <script type=”text/javascript” src=”../../jqwidgets/jqxlistbox.js”></script>
    <script type=”text/javascript” src=”../../jqwidgets/jqxgrid.edit.js”></script>
    <script type=”text/javascript” src=”../../jqwidgets/jqxdropdownlist.js”></script>
    <script type=”text/javascript” src=”../../jqwidgets/jqxcombobox.js”></script>
    <script type=”text/javascript” src=”../../jqwidgets/jqxpanel.js”></script>
    <script type=”text/javascript” src=”../../scripts/demos.js”></script>
    <script type=”text/javascript”>
    $(document).ready(function () {
    var data = ‘[{ “Country”: “Belgium”, “City”: “Brussels”, “Code”: “1234”}, {“Country”: “France”, “City”: “Paris”, “Code”: “1432”}, {“Country”: “USA”, “City”: “Washington”, “Code”: “1342”}]’;
    // prepare the data
    var source =
    {
    datatype: “json”,
    datafields: [
    { name: ‘Code’, type: ‘string’ },
    { name: ‘Country’, type: ‘string’ },
    { name: ‘City’, type: ‘string’ },
    ],
    localdata: data,

    // abdo
    updaterow: function (rowid, rowdata, commit) {
    var uid = rowdata.uid || rowid;
    alert(‘uid: ‘ + rowdata.uid + ‘ | rowid: ‘+rowid);
    console.log(rowdata);

    commit(true);

    var rowdata_0 = $(‘#jqxgrid’).jqxGrid(‘getrowdata’, 0);
    var rowdata_3 = $(‘#jqxgrid’).jqxGrid(‘getrowdata’, 3);
    console.log({
    rowdata_0: rowdata_0,
    rowdata_3: rowdata_3
    });

    return true;
    },
    };
    var dataAdapter = new $.jqx.dataAdapter(source);

    $(“#jqxgrid”).jqxGrid(
    {
    width: 400,
    source: dataAdapter,

    editable: true,
    autoheight: true,
    columns: [
    {
    text: ‘Code’, datafield: ‘Code’, width: 100,
    },
    {
    text: ‘Country’, datafield: ‘Country’, width: 150, columntype: ‘combobox’,
    cellvaluechanging: function (row, datafield, columntype, oldvalue, newvalue) {
    if (newvalue != oldvalue) {
    $(“#jqxgrid”).jqxGrid(‘setcellvalue’, row, “City”, “Select a city…”);
    };
    }
    },
    {
    text: ‘City’, datafield: ‘City’, width: 150, columntype: ‘combobox’,
    initeditor: function (row, cellvalue, editor, celltext, cellwidth, cellheight) {
    var country = $(‘#jqxgrid’).jqxGrid(‘getcellvalue’, row, “Country”);
    var city = editor.val();

    var cities = new Array();
    switch (country) {
    case “Belgium”:
    cities = [“Bruges”, “Brussels”, “Ghent”];
    break;
    case “France”:
    cities = [“Bordeaux”, “Lille”, “Paris”];
    break;
    case “USA”:
    cities = [“Los Angeles”, “Minneapolis”, “Washington”];
    break;
    };

    editor.jqxComboBox({ autoDropDownHeight: true, source: cities });
    if (city != “Select a city…”) {
    var index = cities.indexOf(city);
    editor.jqxComboBox(‘selectIndex’, index);
    }
    }
    },
    ],

    // abdo
    editmode: ‘selectedcell’,
    selectionmode: ‘singlerow’,
    });

    // abdo
    $(‘#addrow’).bind(‘click’, function() {
    var datarow = {};
    $(“#jqxgrid”).jqxGrid(“addrow”, null, datarow, “first”);
    });

    });
    </script>
    </head>
    <body class=’default’>
    <div id=”jqxgrid”>
    </div>

    <button id=”addrow” style=”margin-top: 10px”>add row</button>
    </body>
    </html>


    Abdo
    Participant

    can anyone help me on this, i am not sure if it’s a framework bug or am i missing something…thanks


    Hristo
    Participant

    Hello Abdo,

    Thank you for the interest, we will discuss this case.
    I would like to suggest you implement addrow callback and as a workaround, you could use generated from the base IDs (in an additional column) as a workaround.
    You should include id field in the DataAdapter.

    datatype: "json",
    datafields: [
    	{ name: 'Code', type: 'string' },
    	{ name: 'Country', type: 'string' },
    	{ name: 'City', type: 'string' },
    ],
    id: 'Code',
    localdata: data,

    Also, I would suggest you look at this topic, it shows an additional parameter that is add with new ID commit(true, newID);.
    http://www.jqwidgets.com/community/topic/getting-the-database-generated-id-when-adding-row/#post-52646

    Best Regards,
    Hristo Hristov

    jQWidgets team
    http://www.jqwidgets.com


    Abdo
    Participant

    Thanks Hristo,

    I will try the workaround and let you know


    Abdo
    Participant

    Hi Hristo,

    After reviewing the topic you sent in the previous post, I realized that:
    1. He is doing cruid on a one row basis so he don’t use any buffer
    2. He don’t have any combobox in his grid

    In such case i have no problem but what I want to achieve is to be able to add one or multiple rows, edit other existing rows and maybe delete others than commit all the changes to the database on one ajax call. For this purpose I am using the js buffer.

    I tried to implement addrow and the commit(true, newID) and it didn’t work. In fact the problem isn’t on addrow itself but onchange of a combobox in a new row. If no combobox in the grid the script works fine.

    Thanks again for your help and will appreciate if you have any solution or suggestion.


    Hristo
    Participant

    Hello Abdo,

    I would like to suggest you use addrow([row1, row2...]) and deleterow([row1, row2...]) as an array of rows.
    Also, like I said in the previous post you could use this additional datafield 'Code' with id: 'Code' and you could check all records by this and after that to do your logic with AJAX.

    Best Regards,
    Hristo Hristov

    jQWidgets team
    http://www.jqwidgets.com

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.