Update MySql with value of CheckBox

Update MySql with value of CheckBox

finandofinando Posts: 3Questions: 1Answers: 0
edited May 2014 in DataTables 1.9

Hello to all.
I'm new with this, so excuse me if the question is too simple.

I have the following situation.

$(document).ready(function() {
                var oTable = $('#example').dataTable( {
                    "bProcessing": true,
                    "bServerSide": true,
                    "sPaginationType": "full_numbers",
                    "oLanguage": {
                        "sSearch": "Localizar:",
                        "sLoadingRecords": "Aguarde - carregando..."
                    },                          
                    "sAjaxSource": "Carga_infos.php",
                    "aoColumns": [
                          {"sClass": "readonly"},//ID    
                          {"sClass": "readonly"},//Name
                          {"sClass": "readonly"},//Job
                          {"sClass": "readonly"},//Email
                          {"sClass": "readonly"},//UserId
                          {"sClass": "readonly"},//CC
                          {"sClass": "readonly"},//Area
                          {},//Doc
                          {},//Fone
                          {},
                         {"fnRender": function (oObj) {
                               return "<input type='checkbox' name='check'>";
                            },
                            "sClass": "readonly",
                            "bSearchable": false,
                            "bSortable": false
                            }//checkbox
                     ],
                    "fnDrawCallback": function () {
                        $('#example tbody td').not(".readonly").editable( 'UpdateData.php', {
                            "callback": function( sValue, y ) {                         
                            oTable.fnDraw();
                            },
                            "submitdata": function ( value, settings ) {
                            var rowData = oTable.fnGetData( $(this).parents('tr')[0] );                                         
                                return {
                                    "rowId":rowData[0],
                                    "row": oTable.fnGetPosition( this )[0],
                                    "column": oTable.fnGetPosition( this )[1]
                                };
                            },
                            "height": "14px"
                        } );
                    }
                } );
            } );

My question is.
How do I get the CheckBox is checked or not to update the database?

"submitdata": function ( value, settings ) {
                            var rowData = oTable.fnGetData( $(this).parents('tr')[0] );
                                            
                                return {
                                    "rowId":rowData[0],
                                    "row": oTable.fnGetPosition( this )[0],
                                    "column": oTable.fnGetPosition( this )[1],
                                    "checkbox":__________????
                                };

Thanks.

Answers

  • finandofinando Posts: 3Questions: 1Answers: 0

    Any tips?

    I have not found a solution to let the editable checkbox and update the database.

    If I remove the ReadyOnly class appears the HTML code.

  • finandofinando Posts: 3Questions: 1Answers: 0
    edited May 2014

    There's no way to get the value of checkbox on editable field.

    So I did different.

    $('#example tbody').on('click', ':checkbox', function() {
    if ($(this).attr('checked')){
    
    // unchecked becomes checked here take CHECKED action
    var row = $(this).closest('tr').get(0);
    var aPos = oTable.fnGetPosition(row);
    var aData = oTable.fnGetData(aPos);
    $.ajax({
    type:'POST',
    url: 'update.php',
    data: 'id='+aData[0]+'&check=1'
    });
    
    } else {
    
    // checked becomes unchecked here take UNCHECKED action
    var row = $(this).closest('tr').get(0);
    var aPos = oTable.fnGetPosition(row);
    var aData = oTable.fnGetData(aPos);
    $.ajax({
    type:'POST',
    url: 'update.php',
    data: 'id='+aData[0]+'&check=0'
    });
    }
    });
    

    Works fine.

This discussion has been closed.