mardi 5 mai 2015

JQGrid PHP onclick update status in database

I"m showing status (active/inactive) from database and display in table as a column. I want to make it as checked if the status is active whereas the button must be unchecked if the status is inactive. User must be able to check the checkbox and it must update in the database.

I can display the checkbox button but unable to trigger the event. Been trying for days. But still no luck. Any help much appreciated. Thanks a lot.

$grid->SelectCommand = 'SELECT CustomerID, CompanyName, Phone, PostalCode,            Country, City, Status FROM customers';
$grid->table = 'customers';
$grid->setPrimaryKeyId('CustomerID');
$grid->serialKey = false;
$grid->dataType = 'json';
$grid->setColModel();
$grid->setUrl('grid.php');
$grid->setGridOptions(array(
"caption"=>"This is custom Caption",
"rowNum"=>10,
"hoverrows"=>true,
"rowList"=>array(10,20,50),
"sortname"=>"CustomerID",
"rownumbers"=>true,
"rownumWidth"=>35,
"multiselect"=>true,
"toppager"=>true,
"height"=>"auto",
"autowidth"=>true,
"shrinkToFit"=>true,
"hoverrows"=>true
));

$grid->setColProperty('Status',array("name"=>"enbl","index"=>"enbl","formatter"=>"checkbox",
"editoptions"=>array("value"=>"1:0"),
"formatoptions"=>array("disabled"=>false)));

$getColumnIndexByName = <<< BEFORESHOW
function(grid, columnName) {
    var cm = grid.jqGrid('getGridParam', 'colModel'), i, l;
    for (i = 0, l = cm.length; i < l; i += 1) {
        if (cm[i].name === columnName) {
            return i; // return the index
        }
    }
    return -1;
}
BEFORESHOW;

$loadComplete = <<< LOADCOMPLETE
function () {
var iCol = getColumnIndexByName ($(this), 'enbl'), rows = this.rows, i, c = rows.length;
for (i = 0; i < c; i += 1) {
    $(rows[i].cells[iCol]).click(function (e) {
        var id = $(e.target).closest('tr')[0].id,
            isChecked = $(e.target).is(':checked');
        alert('clicked on the checkbox in the row with id=' + id +
              '\nNow the checkbox is ' +
              (isChecked? 'checked': 'not checked'));
    });
}
}
LOADCOMPLETE;




Aucun commentaire:

Enregistrer un commentaire