Creating an 'Update all Records' Button

Creating an 'Update all Records' Button

PeteBPeteB Posts: 38Questions: 0Answers: 0
edited May 2012 in General
I'd like some newbie help please.

I have a dataTable which displays Person records. Each row contains a column for a 1-char field (possible values= Y/N).
I'd like to know the optimum way of placing a button on my table (or even just on the webpage!) which executes the MySQL "Update sourcetable set yesnoflag = 'N'" and then redisplays the table.

So far I have an extended TableTools 'ajax' button which calls a .php file. But although this successfully updates the underlying source table it gives an error: "Error detected when sending table data to server" and it does not refresh the table.

Any pointers to a solution would be appreciated. Apologies for not putting up my code, but I didn't want to prejudice any answers.

Thanks,
Pete.

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    The Ajax button sounds like a reasonable approach, but you'll need to modify it a bit - specifically the fnClick function - https://github.com/DataTables/TableTools/blob/master/media/js/TableTools.js#L2443 (just use the fnClick option in your 'extends' rather than changing the core). You'll need to Ajax send your data and then in the return update your table suitably for what you want (fnUpdate as you say would probably be best).

    Allan
  • PeteBPeteB Posts: 38Questions: 0Answers: 0
    Thanks, I am now not getting any errors. - I click the button and get the "Ajax complete" message.

    Refreshing the page shows that the source data has been updated.

    How do I get the table to referesh automatically?

    My PHP file is very simple: [code] include ('include/conn.php');
    $sQuery = "UPDATE $app_players SET yesnoflag = 'N'";
    $rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
    echo json_encode($rResult); [/code]
    My Button definition is: [code] { "sExtends": "ajax",
    "sAjaxUrl": "test4.php",
    "sButtonText": "test4"} [/code]
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Is it an Ajax sourced table? In which case the fnReloadAjax plug-in would be best.

    Allan
  • PeteBPeteB Posts: 38Questions: 0Answers: 0
    Allan,

    yes, it is Ajax sourced. I 'm using one of my Editor modules: DTE_players.

    I tried this:[code] { "sExtends": "ajax",
    "sAjaxUrl": "test4.php",
    "sButtonText": "test1",
    "fnComplete": function() {oTable.fnReloadAjax("DTE_players.php") }
    } [/code]

    but got a "oTable.fnReloadAjax is not a function" error message.
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Did you install the plug-in: http://datatables.net/plug-ins/api#fnReloadAjax ?

    Allan
  • PeteBPeteB Posts: 38Questions: 0Answers: 0
    oops, well spotted!

    I have now and it works fine.

    Thanks, for all the help.
This discussion has been closed.