//例子
var products = [
{productid:'FI-SW-01',name:'Koi'},
{productid:'K9-DL-01',name:'Dalmation'},
{productid:'RP-SN-01',name:'Rattlesnake'},
{productid:'RP-LI-02',name:'Iguana'},
{productid:'FL-DSH-01',name:'Manx'},
{productid:'FL-DLH-02',name:'Persian'},
{productid:'AV-CB-01',name:'Amazon Parrot'}
];
//状态
var status =[
{id:'1',name:'可用'},
{id:'2',name:'禁用'}
];
//题目分类
function getCategoory(){
var url='';
$.get(url,function(){
})
}
var scname =[
{id:'1',name:'一级'},
{id:'2',name:'二级'}
];
//题型
var qtname =[
{id:'1',name:'单选'},
{id:'2',name:'多选'}
];
var htname =[
{id:'1',name:'低'},
{id:'2',name:'中'},
{id:'3',name:'高'}
];
var butt =[
{id:'1',name:'保存'},
{id:'2',name:'详情'},
{id:'3',name:'预览'}
];
//增加数据
function add(){
$('#ff').form('submit',{
url:'edu_Teacher.php?ajax=1&action=add',
onSubmit:function(){
return $(this).form('validate');
},
success:function(data){
$.messager.alert('Info', data, 'info');
$('#dlg').window('close');
}
});
$('#tt').datagrid('reload');
}
//删除
function deleterow(index){
$.messager.confirm('操作确认','确定删除么?',function(r){
if (r){
var row = $('#tt').datagrid('getSelected');
var url = 'edu_Teacher.php?action=del&ajax=true&id=' + row.id;
$.get(url,function(rs){
if(rs='ok')
{
$('#tt').datagrid('deleteRow', index);
updateActions();
}
})
}
});
}
function productFormatter(value){
for(var i=0; i<products.length; i++){
if (products[i].productid == value) return products[i].name;
}
return value;
}
function action(value,row,index){
if (row.editing){
var s = '<a href="#" onclick="saverow('+index+')">Save</a> ';
var c = '<a href="#" onclick="cancelrow('+index+')">Cancel</a>';
return s+c;
} else {
var e = '<a href="#" onclick="editrow('+index+')">Edit</a> ';
var d = '<a href="#" onclick="deleterow('+index+')">Delete</a>';
return e+d;
}
}
//输出object
function dump_obj(myObject) {
var s = "";
for (var property in myObject) {
s = s + "\n "+property +": " + myObject[property] ;
}
alert(s);
}
//更新
function updateAjax(){
$('#editform').form('submit',{
url:'edu_Teacher.php?ajax=1&action=edit',
onSubmit:function (){
return $(this).form('validate');
},
success:function (data){
$.messager.alert('Info',data,'info');
$('edit').window('close');
}
})
$('#tt').datagrid('reload');
}
//修改
function editrow(index){
$('#tt').datagrid('selectRow',index);
var row = $('#tt').datagrid('getSelected',index);
$('#edit').dialog('open');//此方法需要改进成参数设置
$('#editform').form('load',{
id:row.id,
name:row.sname,
face:row.face,
description:row.description,
rating:row.rating,
scid:row.scid,
tag:row.tag
});
}
//保存
function saverow(index){
$('#tt').datagrid('acceptChanges');
var row = $('#tt').datagrid('getSelected');
$('#tt').datagrid('endEdit', index);
if(row){
$.get('edu_Teacher.php?ajax=1&action=edit&name=' + row.qname +
'&id=' + row.id +
'&content=' + row.content +
'&qtid=' + row.qtname +
'&htid=' + row.htname + '&status=' + row.status +
'&scid=' + row.scname , function(r){
if(r){
$.messager.alert('提示','成功');
}
})
}
$('#tt').datagrid('reload');
}
//cancel
function cancelrow(index){
$('#tt').datagrid('cancelEdit', index);
}
function updateActions(){
var rowcount = $('#tt').datagrid('getRows').length;
for(var i=0; i<rowcount; i++){
$('#tt').datagrid('updateRow',{
index:i,
row:{action:''}
});
}
}
function getSelections(){
var ids = [];
var rows = $('#tt').datagrid('getSelections');
for(var i=0;i<rows.length;i++){
ids.push(rows[i].id);
}
//alert(ids.join(':'));
return ids;
}
$(function(){
var lastIndex;
$('#tt').datagrid({
toolbar:[{
text:'新增',
iconCls:'icon-add',
handler:function(){
$('#dlg').dialog('open');
}
},'-',{
text:'删除',
iconCls:'icon-remove',
handler:function(){
$('#dlg').window('open');
}
},'-',{
text:'保存',
iconCls:'icon-save',
handler:function(){
$('#tt').datagrid('acceptChanges');
}
},'-',{
text:'撤销',
iconCls:'icon-undo',
handler:function(){
$('#tt').datagrid('rejectChanges');
}
},'-',{
text:'getChanges',
iconCls:'icon-search',
handler:function(){
var rows = $('#tt').datagrid('getChanges');
alert('changed rows: ' + rows.length + ' lines');
}
}],
columns:[[
// {field:'ck',checkbox:true},
{field:'id',title:'讲师ID',width:60},
{field:'name',title:'讲师姓名',width:200,editor:'text'},
{field:'rating',title:'推荐度',width:180,align:'right',editor:{type:'combotree',options:{valueField:'id',textField:'name',url:'../data/edu_json/categoryTree.json',required:true}}},
{field:'addby',title:'添加人',width:200,editor:'text'},
{field:'addtime',title:'添加时间',width:200,editor:'text'},
{field:'action',title:'操作',width:80,align:'center',
formatter:function(value,row,index){
if (row.editing){
var s = '<a href="#" onclick="saverow('+index+')">保存</a> ';
var c = '<a href="#" onclick="cancelrow('+index+')">取消</a>';
return s+c;
} else {
var e = '<a href="#" onclick="editrow('+index+')">修改</a> ';
var d = '<a href="#" onclick="deleterow('+index+')">删除</a>';
return e+d;
}
}
}
]],
onBeforeLoad:function(){
$(this).datagrid('rejectChanges');
}
});
$('#dlg').dialog('close');//此方法需要改进成参数设置
$('#edit').dialog('close');//此方法需要改进成参数设置
});
PHP================================================================================================================
<?php
require_once(dirname(__FILE__).'/config.php');
require_once(DEDEINC."/datalistcp.class.php");
class KnowledgePoint
{
private function D()
{
$d = new DedeSql(FALSE);
return $d;
}
//订单列表
public function viewAll()
{
$dl = new DataListCP();
$dl->pageSize = 30;
$dl->SetTemplate('./templets/edu_Order.htm');
$sql="select `orderid`,`buyerid`,`productid`,`count`,`price`,`status`,`paytype`,`producttype`,`terminal`,`sellerid`,`time` from `edu_user_order` order by orderid desc";
$dl->SetSource($sql);
if($_REQUEST['ajax']!='')
{
$dl->PreLoad();
$row = $dl->GetArcList();
$data = new stdClass();
foreach($row as $s)
{
$lists[]=$s;
}
$data->rows = $lists;
exit( json_encode($data));
}
$dl->Display();//显示页面
}
}
$KnowledgePoint = new KnowledgePoint();
if (isset($_REQUEST['action'])&&method_exists($KnowledgePoint,$_REQUEST['action']))
{
$KnowledgePoint->$_REQUEST['action']();
}
else
{
$KnowledgePoint->viewAll();
}
?>