mercredi 24 juin 2015

jquery datatable checkbox click to select a row

I have a jquery datatable with checkboxes in first column. For each checkbox select/deselect I want to update a status field of corresponding row in database. I could attach click event handler to the checkboxes. With each checkbox click, I want to

  1. mark the row containing a checked checkbox as selected.
  2. Get the row data associated with clicked checkbox.

The code I have done so far:

$('#newItemBasketTab').dataTable({
    "fnDrawCallback": function( oSettings ) {
       $('.ibchkclass').click(function() 
       {
          updateItemBasket(this);
       });
    },

    "aaData": result.itembasketdata,
    "aoColumnDefs":
    [
       {"aTargets": [0],"width": "5%","sClass": "centre_class","mData": "item_basket_id",
        "mRender": function ( data, type, full ){
          var checkedStatus = '';
          if(data != null) { checkedStatus = "checked"; }
          return "<input type='checkbox' class=\"ibchkclass\" id=\"chk_" + full.id1 + "_" + full.id2 + "\" " + checkedStatus + ">";
         }
       },
       {"aTargets": [1],"width": "35%","mData": "name"},
       {"aTargets": [2],"width": "10%","sClass": "price_class", "mData": "prod_quantity"},
       {"aTargets": [3],"width": "10%", "sClass": "price_class", "mData": "prod_value"}
    ]
});

function updateItemBasket(cb)
{
    var cbid = cb.id;
    if( $('#'+cbid).is(':checked') == true)
    {
        alert('true');
        //Select respective row
        //Get item_basket_id, prod_quantity and prod_value
    }
    else
    {

    }
}

Thanks.




Aucun commentaire:

Enregistrer un commentaire