Jeditable and DataTables - Page 2

Jeditable and DataTables

2»

Replies

  • stobywanstobywan Posts: 28Questions: 0Answers: 0
    edited January 2011
    this is the file I have in the jeditable java script initialisation as "server_processing_post.php

    "[code]<?php



    /* Array of database columns which should be read and sent back to DataTables. Use a space where
    * you want to insert a non-database field (for example a counter or static image)
    */
    $aColumns = array ( 'id', 'product_name', 'price', 'taxable_goods', 'details', 'category', 'subcategory', 'ship_weight', 'sale_price');

    /* Indexed column (used for fast and accurate table cardinality) */
    $sIndexColumn = "id";

    /* DB table to use */
    $sTable = "products";





    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
    die( 'Could not open connection to server' );

    mysql_select_db( $gaSql['db'], $gaSql['link'] ) or
    die( 'Could not select database '. $gaSql['db'] );


    /*
    * Paging
    */
    $sLimit = "";
    if ( isset( $_POST['iDisplayStart'] ) && $_POST['iDisplayLength'] != '-1' )
    {
    $sLimit = "LIMIT ".mysql_real_escape_string( $_POST['iDisplayStart'] ).", ".
    mysql_real_escape_string( $_POST['iDisplayLength'] );
    }


    /*
    * Ordering
    */
    if ( isset( $_POST['iSortCol_0'] ) )
    {
    $sOrder = "ORDER BY ";
    for ( $i=0 ; $i
  • allanallan Posts: 63,414Questions: 1Answers: 10,454 Site admin
    You might want to edit that comment to remove your Database login information :-)

    It doesn't explain where $id is coming from though - which is there you are getting the error. Were are you assigning $id to a MySQL result.

    Actually - given that you are using server-side processing - you don't need that at all. Just remove everything from inside the table's tbody tag (i.e. the do {} while() loop).

    Allan
  • stobywanstobywan Posts: 28Questions: 0Answers: 0
    Ok I removed the stuff from and the assoc so no more errors but now when I go to edit a row it
    and I am trying this new post php script more similar to the editable_ajax.php

    "[code]
    <?php


    if (isset($_POST["value"]))

    $db_host = "*****";
    // Place the username for the MySQL database here
    $db_username = "*****";
    // Place the password for the MySQL database here
    $db_pass = "*****";
    // Place the name for the MySQL database here
    $db_name = "*****";

    // Run the actual connection here
    mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql");
    mysql_select_db("$db_name") or die ("no database");



    #GET POST'D VALUES
    $id = $_POST["id"];
    $value = $_POST["value"];


    $sql=mysql_query("UPDATE products SET product_name='$value', price='$value', category='$value', subcategory='$value', details='$value', sale_price='$value', ship_weight='$value', taxable_goods='$value' WHERE id='$id'");




    echo $value.' (updated)';



    ?>
    [/code]"
  • allanallan Posts: 63,414Questions: 1Answers: 10,454 Site admin
    Given that 'row_id' is being sent, $id = $_POST["id"]; looks a bit suspect to me. Is there a reason you are using that, rather than $id = $_POST["row_id"];?

    Allan
  • stobywanstobywan Posts: 28Questions: 0Answers: 0
    No reason... so I changed it to your suggestion so when I update the table it flashes the update for 1 millisecond then returns to the original
  • stobywanstobywan Posts: 28Questions: 0Answers: 0
    Ok so I know that it is sending the "row_id" and it is sending the "value" that I am typing into jeditable....for the POST to receive but there is an "id" being submitted as well but it is blank with no value. I figure I have to tell the database wich row_id it is and which cell "ie product_name, price ect.." to put the newvalue into maybe i am confusing the db?
  • stobywanstobywan Posts: 28Questions: 0Answers: 0
    I got it!

    the php script is working
    Once i got the Value and the row id varibles going I had to add a column atribute to the jquery so i could create
    a if ifelse column condition but know it works .....


    Thanks I learned some neat stuff and accomplished my goal!
  • stobywanstobywan Posts: 28Questions: 0Answers: 0
    edited January 2011
    http://datatables.net/examples/api/row_details.html
    now How can I get the row_details script to blend into this Script?

    "[code]$(document).ready(function() {
    var oTable = $('#example').dataTable( {
    "bJQueryUI": true,
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "server_processing.php",
    "sPaginationType": "full_numbers",
    "fnDrawCallback": function () {
    //alert( 'Number of rows: '+ this.fnGetNodes() );
    $('td', this.fnGetNodes()).editable( 'editable_ajax.php', {
    "callback": function( sValue, y ) {
    var aPos = oTable.fnGetPosition( this );
    oTable.fnUpdate( sValue, aPos[0], aPos[1] );
    },
    "submitdata": function ( value, settings ) {
    //alert( 'Got ID of: '+oTable.fnGetData( this.parentNode )[0] );
    return { "row_id": oTable.fnGetData( this.parentNode )[0],
    "column": oTable.fnGetPosition( this )[2]};
    },
    "height": "14px"
    } );
    }
    });
    });

    [/code]"
  • stobywanstobywan Posts: 28Questions: 0Answers: 0
    Would I be able to use row details API along with my server side jeditable table really I just want to add in an image pop up but my images are not stored in the data base they are in a file on the server....
  • allanallan Posts: 63,414Questions: 1Answers: 10,454 Site admin
    The key thing here is to not apply the jEditable handler to the column you want the row details icon on (usually the first). Then you should be able to use the code given more or less as is. Try this for the selector: $('td:gt(0)', this.fnGetNodes())

    I'm not certain that will work - you might need a loop over the TR nodes and then do the above, but that's the general idea :-)

    Allan
  • stobywanstobywan Posts: 28Questions: 0Answers: 0
    the code you provided does not seem to stop jeditable can you explain a bit further here is my script
    "[code]

    $(document).ready(function() {
    var oTable = $('#example').dataTable( {

    "bJQueryUI": true,
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "server_processing.php",
    "sPaginationType": "full_numbers",
    "fnDrawCallback": function () {
    $('td:gt(0)', this.fnGetNodes())
    //alert( 'Number of rows: '+ this.fnGetNodes() );
    $('td', this.fnGetNodes()).editable( 'editable_ajax.php', {


    "callback": function( sValue, y ) {
    var aPos = oTable.fnGetPosition( this );
    oTable.fnUpdate( sValue, aPos[0], aPos[1] );

    },

    "submitdata": function ( value, settings ) {
    //alert( 'Got ID of: '+oTable.fnGetData( this.parentNode )[0] );
    return { "row_id": oTable.fnGetData( this.parentNode )[0],
    "column": oTable.fnGetPosition( this )[2]};
    },
    "height": "16px"
    } );
    }


    });
    });[/code];
  • allanallan Posts: 63,414Questions: 1Answers: 10,454 Site admin
    $('td:gt(0)', this.fnGetNodes()) in the code you've got above doesn't do anything :-)

    Add it in place of $('td', this.fnGetNodes()), which is what I was trying to say - sorry I wasn't clear enough. If that doesn't work (i.e. it might only stop the first TD in the whole table - I can't quite remember how jQuery works here) you'd need to put in something like: $(this.fnGetNodes()).each( function () { $('td:gt(0)', this).editable....

    Allan
This discussion has been closed.