jQuery UI Widgets Forums Grid Delete Grid Row Issue (PHP)

Tagged: , , ,

This topic contains 1 reply, has 2 voices, and was last updated by  Peter Stoev 9 years, 2 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • Delete Grid Row Issue (PHP) #64279

    claudioandres
    Participant

    Hello, I decided to write after a lot of week spent and many forum topics readed but I couldn’t fix my problem. I reviewed the code for entire weeks and I don’t see the error. The delete row function don’t work… please review it and help me

    $(document).ready(function () {

    var source =
    {
    // contentType: “application/json; charset=utf-8”,
    datatype: “json”,
    cache: false,
    datafields: [
    { name: ‘ID’},
    { name: ‘Cliente’, type: ‘string’ },
    { name: ‘Traking’, type: ‘string’ },
    { name: ‘Descripcion’, type: ‘string’ },
    { name: ‘Piezas’, type: ‘string’},
    { name: ‘Valor’, type: ‘string’},
    { name: ‘Orden’, type: ‘string’ },
    { name: ‘Transportista’},
    { name: ‘Fecha’, type: ‘date’ },
    { name: ‘Status’},
    { name: ‘Envio’},
    { name: ‘Asegurar’}
    ],
    id: ‘ID’,
    url: ‘jqw-data-prealertas.php’,
    pagenum: 0,
    pagesize: 15,

    deleterow: function (rowid, commit) {
    // synchronize with the server – send delete command
    var data = “delete=true&” + $.param({ ID: rowid });
    $.ajax({
    dataType: ‘json’,
    url: ‘jqw-data-prealertas.php’,
    cache: false,
    data: data,
    success: function (data, status, xhr) {
    // delete command is executed.
    commit(true);
    },
    error: function (jqXHR, textStatus, errorThrown) {
    commit(false);
    }
    });
    },

    updaterow: function (rowid, rowdata, commit) {
    // synchronize with the server – send update command
    // decodeURIComponent(escape(VAR)) unescape(encodeURIComponent(VAR))
    var data = “update=true&” + $.param(rowdata);
    $.ajax({
    //contentType: ‘application/json; charset=utf-8’,
    //contentType: ‘application/x-www-form-urlencoded; charset=UTF-8’,
    contentType: ‘application/json; charset=ISO-8859-1’,
    //type: ‘POST’,
    dataType: ‘json’,
    url: ‘jqw-data-prealertas.php’,
    cache: false,
    data: data,
    success: function (data, status, xhr) {
    // update command is executed.
    commit(true);
    },
    error: function (jqXHR, textStatus, errorThrown) {
    commit(false);
    }
    });
    }
    };

    var dataAdapter = new $.jqx.dataAdapter(source);

    // initialize jqxGrid
    $(“#jqxgrid”).jqxGrid(
    {
    source: dataAdapter, // source
    theme: ‘office’,
    width: 880,
    height: 520,
    //autoheight: true,
    showfilterrow: true,
    filterable: true,
    columnsresize: true,
    pageable: true,
    sortable: true,
    altrows: true,
    enabletooltips: true,
    editable: true,
    //editmode: ‘selectedcell’, // ‘dblclick’ ‘click’
    //showaggregates: true,
    //selectionmode: ‘multiplecellsadvanced’, // multiplecellsextended
    showtoolbar: true,
    columns: [
    { text: ‘ID’, datafield: ‘ID’, width: 40, hidden: true },
    { text: ‘Cliente’, datafield: ‘Cliente’, filtertype:’textbox’, width: 50 },
    { text: ‘Traking’, datafield: ‘Traking’, filtertype:’textbox’, width: 80 }, // cellsrenderer: cellsrenderer,
    { text: ‘Descripcion’, datafield: ‘Descripcion’, filtertype: ‘textbox’, width: 180 },
    { text: ‘Piezas’, datafield: ‘Piezas’, filtertype: ‘number’, width: 45 },
    { text: ‘Valor’, datafield: ‘Valor’, filtertype:’textbox’, width: 60 },
    { text: ‘Orden’, datafield: ‘Orden’, filtertype:’textbox’, width: 110 },
    { text: ‘Transportista’, datafield: ‘Transportista’, columntype: ‘dropdownlist’, filtertype:’checkedlist’, width: 85 },
    { text: ‘Fecha’, datafield: ‘Fecha’, filtertype:’textbox’, columntype: ‘datetimeinput’, cellsformat: ‘yyyy-MM-dd’, width: 80 },
    { text: ‘Status’, datafield: ‘Status’, columntype: ‘dropdownlist’, filtertype:’checkedlist’, width: 80 },
    { text: ‘Envio’, datafield: ‘Envio’, columntype: ‘dropdownlist’, filtertype:’checkedlist’, width: 50 },
    { text: ‘Asegurar’, datafield: ‘Asegurar’, columntype: ‘dropdownlist’, filtertype:’checkedlist’, width: 60 }
    ]
    });

    $(“#clearfilter”).jqxButton({ theme: ‘energyblue’ });
    $(“#deleterowbutton”).jqxButton({ theme: ‘energyblue’ });
    $(“#updaterowbutton”).jqxButton({ theme: ‘energyblue’ });

    // update row
    $(“#updaterowbutton”).bind(‘click’, function () {
    //var datarow = generaterow();
    var selectedrowindex = $(“#jqxgrid”).jqxGrid(‘getselectedrowindex’);
    var rowscount = $(“#jqxgrid”).jqxGrid(‘getdatainformation’).rowscount;
    if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
    var id = $(“#jqxgrid”).jqxGrid(‘getrowid’, selectedrowindex);
    $(“#jqxgrid”).jqxGrid(‘updaterow’, id); //, datarow
    }
    });

    // delete row
    $(“#deleterowbutton”).bind(“click”, function () {
    var selectedrowindex = $(“#jqxgrid”).jqxGrid(“getselectedrowindex”);
    var rowscount = $(“#jqxgrid”).jqxGrid(“getdatainformation”).rowscount;
    if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
    var id = $(“#jqxgrid”).jqxGrid(“getrowid”, selectedrowindex);
    $(“#jqxgrid”).jqxGrid(“deleterow”, id);
    }
    });

    // clear filters
    $(‘#clearfilter’).click(function () {
    $(“#jqxgrid”).jqxGrid(‘clearfilters’);
    });
    });

    ——————– And the data file: —————————————

    include(‘jqw-connect.php’);

    #Connect to the database
    //connection String
    $connect = mysql_connect($hostname, $username, $password)
    or die(‘Could not connect: ‘ . mysql_error());
    //select database
    mysql_select_db($database, $connect);
    //Select The database
    $bool = mysql_select_db($database, $connect);
    if ($bool === False){
    print “can’t find $database”;
    }
    // get data and store in a json array
    /*if ($_GET[‘refresh’]==’act’) {
    $query = “SELECT * FROM prealertas WHERE prea_fecha='”.$_GET[‘fecha’].”‘”;
    } else { */
    $query = “SELECT * FROM prealertas ORDER BY prea_fecha DESC”;
    /*}
    $from = 0;
    $to = 30;
    $query .= ” LIMIT “.$from.”,”.$to; */

    if (isset($_GET[‘insert’])) {

    // INSERT COMMAND
    $insert_query = “INSERT INTO prealertas (prea_id, prea_cliente, prea_traking, prea_descripcion, prea_piezas, prea_valor, prea_orden, prea_envio, prea_fecha, prea_status, prea_enviarx, prea_asegurar) VALUES (‘”.$_GET[‘ID’].”‘,'”.$_GET[‘Cliente’].”‘,'”.$_GET[‘Traking’].”‘,'”.$_GET[‘Descripcion’].”‘,'”.$_GET[‘Piezas’].”‘,'”.$_GET[‘Valor’].”‘,'”.$_GET[‘Orden’].”‘,'”.$_GET[‘Transportista’].”‘,'”.$_GET[‘Fecha’].”‘,'”.$_GET[‘Status’].”‘,'”.$_GET[‘Envio’].”‘,'”.$_GET[‘Asegurar’].”‘)”;
    $result = mysql_query($insert_query) or die(“SQL Error 1: ” . mysql_error());
    echo $result;

    } else if (isset($_GET[‘update’])) {

    // UPDATE COMMAND

    $update_query = “UPDATE prealertas SET prea_status='”.$_GET[‘Status’].”‘ WHERE prea_id='”.$_GET[‘ID’].”‘”;
    /*$update_query = “UPDATE prealertas SET prea_cliente='”.$_GET[‘Cliente’].”‘, prea_traking='”.$_GET[‘Traking’].”‘, prea_descripcion='”.utf8_decode($_GET[‘Descripcion’]).”‘, prea_piezas='”.$_GET[‘Piezas’].”‘, prea_valor='”.$_GET[‘Valor’].”‘, prea_orden='”.$_GET[‘Orden’].”‘, regi_envio='”.$_GET[‘Transportista’].”‘, prea_fecha='”.$_GET[‘Fecha’].”‘, prea_status='”.$_GET[‘Status’].”‘, prea_enviarx='”.$_GET[‘Envio’].”‘, prea_asegurar='”.$_GET[‘Asegurar’].”‘ WHERE prea_id='”.$_GET[‘ID’].”‘”;*/
    $result = mysql_query($update_query) or die(“SQL Error 1: ” . mysql_error());
    echo $result;

    } else if (isset($_GET[‘delete’])) {

    // DELETE COMMAND
    $delete_query = “DELETE FROM prealertas WHERE prea_id='”.$_GET[‘ID’].”‘”;
    $result = mysql_query($delete_query) or die(“SQL Error 1: ” . mysql_error());
    echo $result;

    } else {

    $result = mysql_query($query) or die(“SQL Error 1: ” . mysql_error());
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

    $prealerta[] = array(
    ‘ID’ => $row[‘prea_id’],
    ‘Cliente’ => $row[‘prea_cliente’],
    ‘Traking’ => $row[‘prea_traking’],
    ‘Descripcion’ => utf8_encode($row[‘prea_descripcion’]),
    ‘Piezas’ => $row[‘prea_piezas’],
    ‘Valor’ => $row[‘prea_valor’],
    ‘Orden’ => $row[‘prea_orden’],
    ‘Transportista’ => $row[‘prea_envio’],
    ‘Fecha’ => $row[‘prea_fecha’],
    ‘Status’ => $row[‘prea_status’],
    ‘Envio’ => $row[‘prea_enviarx’],
    ‘Asegurar’ => $row[‘prea_asegurar’]
    );
    }
    echo json_encode($prealerta);

    }

    Delete Grid Row Issue (PHP) #64296

    Peter Stoev
    Keymaster

    Hi claudioandres,

    From the client side, the code looks correct. However, your Server Script may require Additional code depending on whether your tables have relationship and whether you’ll need to perform cascade delete. A help topics which shows how to implement the client side is http://www.jqwidgets.com/jquery-widgets-documentation/documentation/phpintegration/php-server-side-grid-crud.htm

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

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

You must be logged in to reply to this topic.