Horizontal scrolling and javascript array

Horizontal scrolling and javascript array

Fabricio_ndasFabricio_ndas Posts: 10Questions: 0Answers: 0
edited September 2011 in General
Hello,
I was looking for an example of Horizontal scrolling and javascript array together in the same table, Because I was trying use both but it didn't worked fine.
Thanks!

Replies

  • allanallan Posts: 63,400Questions: 1Answers: 10,451 Site admin
    It should just be a case of combining these two:

    http://datatables.net/release-datatables/examples/data_sources/js_array.html
    http://datatables.net/release-datatables/examples/basic_init/scroll_xy.html

    What have you got so far?

    Allan
  • Fabricio_ndasFabricio_ndas Posts: 10Questions: 0Answers: 0
    I did it and it worked fine, but I still have two problems...

    First: I'm using the same table that i was using with 1.6 version, I've updated it to 1.8, now when I add a new line dinamically using server processing it doesn't update automatically, it just update if i refresh page or change the sort type.

    Table code:

    [code]
    oTable = $('#grid').dataTable({
    "oLanguage": { "sUrl": "media/language/pt-br2.txt" },
    "sScrollY": 200,
    "sScrollX": "100%",
    "sScrollXInner": "110%",
    "bJQueryUI": false,
    "sPaginationType": "full_numbers",
    "bProcessing": false,
    "bServerSide": true,
    "sAjaxSource": "server_processing_agencias.php",
    "bAutoWidth": false,
    "bLengthChange": true,

    "sDom": '<"top"f<"clear">ip<"clear">> <"bottom"t>',

    "aoColumns": [
    // null,
    { "sTitle": "ID BANCO" , "sWidth": "10%", "bSortable": true, "bVisible": false },
    { "sTitle": "BANCO" , "sWidth": "25%", "bSortable": true, "bVisible": true },
    { "sTitle": "ID" , "sWidth": "5%", "bSortable": false, "bVisible": false },
    { "sTitle": "AGÊNCIA" , "sWidth": "25%", "bSortable": true, "bVisible": true },
    { "sTitle": "NÚMERO" , "sWidth": "5%", "bSortable": false, "bVisible": false },
    { "sTitle": "DIGITO" , "sWidth": "5%", "bSortable": false, "bVisible": false },
    { "sTitle": "LOCAL" , "sWidth": "30%", "bSortable": true, "bVisible": true }

    ],
    "aaSorting": [[ 1, 'asc' ]]
    });

    [/code]

    Save function to add new line:

    [code]
    $("#save").click(function() {

    var str_data = "&table="+encodeURI($("#table").val())+
    "&id="+encodeURI($("#id").val())+
    "&id_banco="+encodeURI($("#id_banco").val())+
    "&numero="+encodeURI($("#numero").val())+
    "&digito="+encodeURI($("#digito").val())+
    "&nome="+encodeURI($("#nome").val())+
    "&local="+encodeURI($("#local").val());
    var r = 0;

    $.ajax({
    type: "POST",
    url: "save.php",
    dataType: 'json',
    data: str_data,
    success: function(msg) {
    oTable.fnDraw();
    }
    });

    $("#edicao").hide();
    $("#listagem").show();
    [/code]

    The second problem is happening with another table then I'll tell later when i get this problem solved
    Thanks for helping and sorry for bother you.
  • allanallan Posts: 63,400Questions: 1Answers: 10,451 Site admin
    That certainly looks like it should work. Are you getting any errors in the Javascript console, or in the XHR returns?

    Allan
  • Fabricio_ndasFabricio_ndas Posts: 10Questions: 0Answers: 0
    Sorry for late, I realized the when run save.php using 1.6 version, the server side processing runs again, it's why table updates, when I change it to 1.8 version it doesn't occur
    I didn't get any errors...

    Server side processing code:

    [code]

    <?php
    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    * Easy set variables
    */

    /* Array of database columns which should be read and sent back to DataTables */
    $aColumns = array( 'idbanco','banco', 'id', 'agencia', 'numero', 'digito', 'local' );

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

    /* Database connection information */
    /*
    $gaSql['user'] = "myuser";
    $gaSql['password'] = "mypassword";
    $gaSql['db'] = "mydb";
    $gaSql['server'] = "myserver";
    */
    include("./conn.php");

    /* REMOVE THIS LINE (it just includes my SQL connection user/pass) */
    //include( $_SERVER['DOCUMENT_ROOT']."/datatables/mysql.php" );


    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    * If you just want to use the basic configuration for DataTables with PHP server-side, there is
    * no need to edit below this line
    */

    /*
    * MySQL connection
    */
    $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( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
    {
    $sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
    mysql_real_escape_string( $_GET['iDisplayLength'] );
    }


    /*
    * Ordering
    */
    if ( isset( $_GET['iSortCol_0'] ) )
    {
    $sOrder = "ORDER BY ";
    for ( $i=0 ; $i
  • allanallan Posts: 63,400Questions: 1Answers: 10,451 Site admin
    If you put in "alert('Hello');" just before this line: oTable.fnDraw(); in your "save" event handler, does the alert show up?

    Allan
  • Fabricio_ndasFabricio_ndas Posts: 10Questions: 0Answers: 0
    Sorry, i was checking the wrong place for errors, i received this error message:
    SyntaxError: JSON.parse: expected property name or '}'

    And no, the alert doesn't shows up, it just happens when i'm using 1.8 version, if i put 1.6 it runs good

    I'm sorry for my fault, I'm new with javascript and php...
  • Fabricio_ndasFabricio_ndas Posts: 10Questions: 0Answers: 0
    Hello,
    Do you have any idea about what is happening?

    Thanks for help, and sorry for bother you
  • Fabricio_ndasFabricio_ndas Posts: 10Questions: 0Answers: 0
    Hello,
    I didn't solved the problem yet. Can you help me please?
  • allanallan Posts: 63,400Questions: 1Answers: 10,451 Site admin
    Sounds like a JSON error to me. What is the JSON response from the server? Run it through http://jsonlint.com to check if it is valid.

    Allan
  • Fabricio_ndasFabricio_ndas Posts: 10Questions: 0Answers: 0
    Allan tanks for response,
    I did as you told me to do and i got the following error message:

    Parse error on line 1:
    <?php/**************
    ^
    Expecting '{', '['


    The problem is that the alert before oTable.fnDraw(); doesn't shows up but it still saves, however, it doesn't update the table.

    Thanks,
    Fabricio
This discussion has been closed.