Unable to get input value from specific columns

Unable to get input value from specific columns

dana_1310dana_1310 Posts: 2Questions: 1Answers: 0
edited October 2014 in Free community support

Hi everyone,actually i'm designing a user permissions, i have already populated the datatables with a list of modules and have add 4 checkbox for add, read, update, delete. Unfortunately i`m unable to get the value true or false of the checkbox for specific rows... Can anyone help thanks...

My html code

    <table class="table table-bordered table-striped table-hover table-heading table-datatable"     id="datatable-2">
                 <thead>
                     <tr>
                           <th><?php echo $this->lang->line('userpermission_code'); ?></th>
                           <th><?php echo $this->lang->line('userpermission_main'); ?></th>
                           <th><?php echo $this->lang->line('userpermission_sub'); ?></th>
                           <th><?php echo $this->lang->line('userpermission_create'); ?></th>
                           <th><?php echo $this->lang->line('userpermission_read'); ?></th>
                          <th><?php echo $this->lang->line('userpermission_update'); ?></th>
                           <th><?php echo $this->lang->line('userpermission_delete'); ?></th>
                    </tr>
                </thead>
                <tbody>

                    <?php foreach($result as $row) { ?>
                    <tr>
                        <td><?php echo $row['Code'] ?></td>
                        <td><?php echo $row['Main'] ?></td>
                        <td><?php echo $row['Sub'] ?></td>
                        <td style="text-align:center;vertical-align:middle;">
                            <input type="checkbox" id="create" name="create">
                        </td>
                        <td style="text-align:center;vertical-align:middle;">
                            <input id="read" type="checkbox" name="read">
                        </td>
                        <td style="text-align:center;vertical-align:middle;">
                            <input id="update" type="checkbox" name="update">
                        </td>
                        <td style="text-align:center;vertical-align:middle;">
                            <input id="delete" type="checkbox" name="delete">
                        </td>
                    </tr>
                    <?php } ?>
                </tbody>
                <tfoot>
                    <tr>
                        <th><?php echo $this->lang->line('userpermission_code'); ?></th>
                        <th><?php echo $this->lang->line('userpermission_main'); ?></th>
                        <th><?php echo $this->lang->line('userpermission_sub'); ?></th>
                        <th><?php echo $this->lang->line('userpermission_create'); ?></th>
                        <th><?php echo $this->lang->line('userpermission_read'); ?></th>
                        <th><?php echo $this->lang->line('userpermission_update'); ?></th>
                        <th><?php echo $this->lang->line('userpermission_delete'); ?></th>
                    </tr>
                </tfoot>
            </table>

my script

<script type="text/javascript">
// Pagination and search code
 function AllTables(){
  TestTable2();
  LoadSelect2Script(MakeSelect2);
 }

 function MakeSelect2(){
  $('select').select2();
     $('.dataTables_filter').each(function(){
      $(this).find('label input[type=text]').attr('placeholder', '<?= $search ?>');
    });
 }

$(document).ready(function() {
// Load Datatables and run plugin on tables 
LoadDataTablesScripts(AllTables);

$('#userpermission').submit(function( event ) {
    event.preventDefault();
    var oTable = $('#datatable-2').dataTable();
    var nlines = $(oTable.fnGetNodes()).length; 

for(var i=0; i<nlines; i++){



    var alldata = [];
    var column0 = oTable.fnGetNodes()[i].cells[0].childNodes[0];
    var column1 = oTable.fnGetNodes()[i].cells[1].childNodes[0];
    var column2 = oTable.fnGetNodes()[i].cells[2].childNodes[0];
    var column3 = oTable.fnGetNodes()[i].cells[3].childNodes[0];

// here i want to retrieve every row into the array
    alldata.push(oTable.$(column0).text(), oTable.$(column1).text(), oTable.$(column2).text(), oTable.$(column3).$('input').val());
    console.log(alldata);


}

});
});

function LoadDataTablesScripts(callback){
function LoadDatatables(){
    $.getScript('<?= base_url() ?>public/plugins/datatables/jquery.dataTables.js', function(){
        $.getScript('<?= base_url() ?>public/plugins/datatables/ZeroClipboard.js', function(){
            $.getScript('<?= base_url() ?>public/plugins/datatables/TableTools.js', function(){
                $.getScript('<?= base_url() ?>public/plugins/datatables/dataTables.bootstrap.js',    callback);
            });
        });
    });
}
if (!$.fn.dataTables){
    LoadDatatables();
}
else {
    if (callback && typeof(callback) === "function") {
        callback();
    }
  }
  }

 function LoadSelect2Script(callback){
 if (!$.fn.select2){
    $.getScript('<?= base_url() ?>public/plugins/select2/select2.min.js', callback);
 }
else {
     if (callback && typeof(callback) === "function") {
        callback();
    }
 }
 }

function TestTable2(){
var asInitVals = [];
var oTable = $('#datatable-2').dataTable( {
    "aaSorting": [[ 0, "asc" ]],
    "sDom": "<'box-content'<'col-sm-6'f><'col-sm-6 text-right'l><'clearfix'>>rt<'box-content'<'col-sm-6'i><'col-sm-6 text-right'p><'clearfix'>>",
    "sPaginationType": "bootstrap",
    "oLanguage": {
        "sSearch": "",
        "sLengthMenu": '_MENU_',
                    "sUrl": "<?= base_url() ?>public/language/<?= $language ?>.txt"


    },
    bAutoWidth: false
});
var header_inputs = $("#datatable-2 thead input");
header_inputs.on('keyup', function(){
    /* Filter on the column (the index) of this element */
    oTable.fnFilter( this.value, header_inputs.index(this) );
})
.on('focus', function(){
    if ( this.className == "search_init" ){
        this.className = "";
        this.value = "";
    }
})
.on('blur', function (i) {
    if ( this.value == "" ){
        this.className = "search_init";
        this.value = asInitVals[header_inputs.index(this)];
    }
});
header_inputs.each( function (i) {
    asInitVals[i] = this.value;
});
}   
 </script>
This discussion has been closed.