EasyUI Forum
September 14, 2025, 07:26:14 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
  Home Help Search Login Register  
  Show Posts
Pages: [1]
1  General Category / EasyUI for jQuery / Re: add/edit/delete/view options in combogrid on: June 12, 2013, 04:11:40 AM
Hi Stworty,

I have this so far:
Code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="keywords" content="jquery,ui,easy,easyui,web">
<meta name="description" content="easyui help you build your web page easily!">
<title>jQuery EasyUI CRUD Demo</title>
<link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/demo/demo.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.min.js"></script>
<script type="text/javascript" src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>

</head>
<body>
<h2>Basic CRUD Application</h2>
<div class="demo-info" style="margin-bottom:10px">
<div class="demo-tip icon-tip">&nbsp;</div>
<div>Click the buttons on datagrid toolbar to do crud actions.</div>
</div>

<table id="dg" title="My Users" class="easyui-datagrid" style="width:700px;height:250px"
url="get_users.php"
toolbar="#toolbar" pagination="true"
rownumbers="true" fitColumns="true" singleSelect="true">
<thead>
<tr>
<th field="firstname" width="50">First Name</th>
<th field="lastname" width="50">Last Name</th>
<th field="phone" width="50">Phone</th>
<th field="email" width="50">Email</th>
</tr>
</thead>
</table>
<div id="toolbar">
<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">New User</a>
<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">Edit User</a>
<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">Remove User</a>
</div>

<div id="dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
closed="true" buttons="#dlg-buttons">
<div class="ftitle">User Information</div>
<form id="fm" method="post" novalidate>
<div class="fitem">
<label>First Name:</label>
<input name="firstname" class="easyui-validatebox" required="true">
</div>
<div class="fitem">
<label>Last Name:</label>
<!--<input name="lastname" class="easyui-validatebox" required="true">-->
<select class="easyui-combogrid" style="width:150px" name="lastname" value="2" data-options=" 
                    panelWidth: 160, 
                    idField: 'id', 
                    textField: 'lastname', 
                    url: 'last_names.json', 
                    columns: [[ 
                        {field:'id',title:'ID',width:40}, 
                        {field:'lastname',title:'Lastname',width:120}, 
                 
                    ]], 
                    fitColumns: true 
                "> 
            </select> 
</div>
<div class="fitem">
<label>Phone:</label>
<input name="phone">
</div>
<div class="fitem">
<label>Email:</label>
<input name="email" class="easyui-validatebox" validType="email">
</div>
</form>
</div>
<div id="dlg-buttons">
<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveUser()">Save</a>
<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">Cancel</a>
</div>
<script type="text/javascript">
var url;
function newUser(){
$('#dlg').dialog('open').dialog('setTitle','New User');
$('#fm').form('clear');
url = 'save_user.php';
}
function editUser(){
var row = $('#dg').datagrid('getSelected');
if (row){
$('#dlg').dialog('open').dialog('setTitle','Edit User');
$('#fm').form('load',row);
url = 'update_user.php?id='+row.id;
}
}
function saveUser(){
$('#fm').form('submit',{
url: url,
onSubmit: function(){
return $(this).form('validate');
},
success: function(result){
var result = eval('('+result+')');
if (result.errorMsg){
$.messager.show({
title: 'Error',
msg: result.errorMsg
});
} else {
$('#dlg').dialog('close'); // close the dialog
$('#dg').datagrid('reload'); // reload the user data
}
}
});
}
function destroyUser(){
var row = $('#dg').datagrid('getSelected');
if (row){
$.messager.confirm('Confirm','Are you sure you want to destroy this user?',function(r){
if (r){
$.post('destroy_user.php',{id:row.id},function(result){
if (result.success){
$('#dg').datagrid('reload'); // reload the user data
} else {
$.messager.show({ // show error message
title: 'Error',
msg: result.errorMsg
});
}
},'json');
}
});
}
}
</script>
<style type="text/css">
#fm{
margin:0;
padding:10px 30px;
}
.ftitle{
font-size:14px;
font-weight:bold;
padding:5px 0;
margin-bottom:10px;
border-bottom:1px solid #ccc;
}
.fitem{
margin-bottom:5px;
}
.fitem label{
display:inline-block;
width:80px;
}
</style>
</body>
</html>
How should I append your code? Do you have a more typed out example?
Thanks
2  General Category / EasyUI for jQuery / datagrid reuseable/repeatable on: June 12, 2013, 01:38:00 AM
I would like to use the datagrid as a function so that I can call it multiple times. The scenario I have in mind is the following:

1. The user opens the page and a datagrid is displayed.
2. When the user wants to add or edit a row the add- or edit-dailog is opened.
3. Some fields may come from another table so they are shown in a combogrid
4. If the user uses the combogrid that grid should also have all the crud options.
5. The user can scroll the combogrid and select an entry or he can edit an entry or he can add an entry.
6. If the user selects an entry than the necessary field should be updated in the edit-dialog.
7. If the user choose to add or edit an entry from the combogrid everything is repeated from step 2.
The application I am building is a rest-application using remote json-data. So for every call to the grid the url is different and should be passed as a parameter to the jqgrid-function. Questions:

1.Can anyone help me in the right direction for steps 4 to 7?
2.How can I add CRUD to the combogrid?
3.How do I achieve that if something is selected from the combogrid the edit/add dialog is updated?
4.Should the data for the other grids allready be loaded on opening the page or can I get them when opening the dialog?
5.How can I set this up dynamically?
Thank you
Kluther
3  General Category / EasyUI for jQuery / add/edit/delete/view options in combogrid on: June 09, 2013, 11:18:50 PM
Is it possible to have the add, edit, view and delete options in the combogrid?
Pages: [1]
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!