jQuery UI Widgets Forums Grid add rows using addrow method

This topic contains 2 replies, has 3 voices, and was last updated by  ismaelnascimento 6 years, 6 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • add rows using addrow method #77580

    omargarro
    Participant

    Hi, I have this grid displaying some plain mysql table: id (int) , name varchar(10)

    Users can add records to this table using my grid (php code server side).
    they can add only one record or several.

    I have problems refreshing the grid when multiple records are inserted. ( when only 1 record is inserted everything works fine)

    My serverside php script ends with something like this:

    <?php
    $pdo->Query( ‘select * from myTable where id IN ( … , … , … , … )’ ); // supose the query is OK.
    $Results = array();
    while( $row = $pdo->getRow() ) {
    $Results[‘data’][] = $row;
    }
    $Results[‘status’] = ‘ok’;
    die( json_encode($Results) );

    ?>

    And my client side (.js)

    $.ajax({
    url: ‘myScript.php’, data: {howManyRecords: $(‘#recs’).val(), name: $(‘#name’).val() }, method: ‘post’,
    success: function( response ) {
    var obj = $.parseJSON(response);

    // let’s collect rows returned
    var rows = new Array();
    $.each( obj.data, function( k, v ) {
    rows.push(v);
    });

    // refresh grid
    $(‘#jqxGrid’).jqxGrid(‘addrow’, null, rows);

    // close modal window
    $(‘#jqxWindow’).jqxWindow(‘hide’);
    }
    })

    My grid refreshes only one record. But if I reload the page ( F5 ), all records are shown.

    What am I missing ???

    thanks in adv

    add rows using addrow method #77602

    Peter Stoev
    Keymaster

    hi omargaro,

    We have online demo: http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/createremoveupdatedata.htm?arctic which demonstrates how to add multiple rows at once in jqxGrid. You may take a look at it and follow the same approach. Also, adding multiple rows on the client side does not depend on the server side.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/

    add rows using addrow method #100801

    ismaelnascimento
    Participant

    @ViewChild(‘myGrid’) grid: jqxGridComponent;

    this.grid.columns = [
    {
    datafield: ‘CODE’,
    text: ‘Code’,
    },
    {
    datafield: ‘DESCRIPTION’,
    text: ‘Description’
    }
    ];

    this.grid.addrow(null,
    { “CODE”: 999,
    “DESCRIPTION”: “My Description”
    }
    );

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

You must be logged in to reply to this topic.