Thursday, March 19, 2015

Jquery (javascript) CRUD using Jeasy UI and CodeIgniter - Part 1

Jquery Script using Jeasyui Grid to send using to Codeigniter



<script type="text/javascript">
var url;
 
function create(){
    jQuery('#dialog-form').dialog('open').dialog('setTitle','Tambah Pegawai');
    jQuery('#form').form('clear');
    url = '<?php echo site_url('wavin/createjson'); ?>';
}
 
function update(){
    var row = jQuery('#datagrid-crud').datagrid('getSelected');
    if(row){
        jQuery('#dialog-form').dialog('open').dialog('setTitle','Edit Pegawai');
        jQuery('#form').form('load',row);
        url = '<?php echo site_url('wavin/updatejson'); ?>/' + row.id;
    }
}
 
function save(){
    jQuery('#form').form('submit',{
        url: '<?php echo site_url('wavin/createjson'); ?>',
        onSubmit: function(){
            return jQuery(this).form('validate');
        },
        success: function(result){
            var result = eval('('+result+')');
            if(result.success){
                jQuery('#dialog-form').dialog('close');
                jQuery('#datagrid-crud').datagrid('reload');
            } else {
                jQuery.messager.show({
                    title: 'Error save Pegawai',
                    msg: result.msg
                });
            }
        }
    });
}
 
function remove(){
    var row = jQuery('#datagrid-crud').datagrid('getSelected');
    if (row){
        jQuery.messager.confirm('Confirm','Yakin hapus Pegawai tersebut?',function(r){
            if (r){
                jQuery.post('<?php echo site_url('mavin/deletejson'); ?>',{id:row.id},function(result){
                    if (result.success){
                        jQuery('#datagrid-crud').datagrid('reload');
                    } else {
                        jQuery.messager.show({
                            title: 'Error',
                            msg: result.msg
                        });
                    }
                },'json');
            }
        });
    }
}
</script>

Hery Purnama 081.223344.506 , IT trainer , Excel / access VBA Macro, MS Project, Primavera,
PHP Ajax Jquery, Google Map API, Google Sketchup3D, Ubuntu, Sencha ExtJS, YII, Code Igniter,
Oracle, SQL Server,
Bandung, Jakarta, Bali, Medan, Surabaya, Yogya, Indonesia

No comments:

Post a Comment