JSFiddle - React, Tailwind, and code Playground
by andruxnet
HTML
<link rel="stylesheet" href="http://www.jeasyui.com/easyui/themes/default/easyui.css">
<link rel="stylesheet" href="http://www.jeasyui.com/easyui/themes/icon.css">
<link rel="stylesheet" href="http://www.jeasyui.com/easyui/demo/demo.css">
<script src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
<script src="http://wptest.andrux.net/jquery.edatagrid.js"></script>
<table id="roles-permissions"></table>
<script>
function updateActions( index ) {
jQuery( '#roles-permissions' ).datagrid( 'updateRow', {
index: index,
row: {}
});
}
function getRowIndex( target ) {
var tr = jQuery( target ).closest( 'tr.datagrid-row' );
return parseInt( tr.attr( 'datagrid-row-index' ) );
}
function editrow( target ) {
jQuery( '#roles-permissions' ).datagrid( 'beginEdit', getRowIndex( target ) );
}
function saverow( target ) {
jQuery( '#roles-permissions' ).datagrid( 'endEdit', getRowIndex( target ) );
}
function cancelrow( target ) {
jQuery( '#roles-permissions' ).datagrid( 'cancelEdit', getRowIndex( target ) );
}
</script>
JavaScript
jQuery( document ).ready( function( $ ) {
$( '#roles-permissions' ).edatagrid({
title: 'Role Permissions',
iconCls: 'icon-edit',
width: 420,
height: 240,
singleSelect: true,
idField: 'role',
columns:[[
{field: 'Role', title: 'Role', width: 100},
{field: 'View', title: 'View', width: 50, align: 'center',
editor: {
type: 'checkbox',
options: {
on: 'yes',
off: 'no'
}
}
},
{field: 'Edit', title: 'Edit', width: 50, align: 'center',
editor: {
type: 'checkbox',
options: {
on: 'yes',
off: 'no'
}
}
},
{field: 'action', title: 'Action', width: 80, align: 'center',
formatter: function( value, row, index ) {
if ( row.editing ) {
var s = '<a class="icon-save" style="text-decoration: none; padding: 0px 5px;" href="#" onclick="saverow( this )"> </a> ';
var c = '<a class="icon-cancel" style="text-decoration: none; padding: 0px 5px;" href="#" onclick="cancelrow( this )"> </a>';
return s + c;
}
else {
var e = '<a class="icon-edit" style="text-decoration: none; padding: 0px 5px;" href="#" onclick="editrow(this)"> </a> ';
return e;
}
}
}
]],
onBeforeEdit: function( index, row ) {
row.editing = true;
updateActions( index );
},
onAfterEdit: function( index, row ) {
row.editing = false;
updateActions( index );
},
onCancelEdit: function( index, row ) {
row.editing = false;
updateActions( index );
},
onEdit: function( index, row ) {
alert('test');
var dg = $( '#roles-permissions' );
dg.datagrid( 'beginEdit', index );
var ed1 = dg.datagrid( 'getEditor', { index: index, field: 'view' });
var ed2 = dg.datagrid( 'getEditor', { index: index, field: 'edit' });
$( ed1.target ).click( function() {
if ( ! $( this ).is( ':checked' ) ) {
$( ed2.target ).prop(...