Skip to content

Instantly share code, notes, and snippets.

@dhoss
Created October 1, 2010 07:12
Show Gist options
  • Save dhoss/605869 to your computer and use it in GitHub Desktop.
Save dhoss/605869 to your computer and use it in GitHub Desktop.
$(function() {
var lastsel;
var rowid;
var rows = $("#tposts").jqGrid('getDataIDs');
console.log("rows: " + rows);
$("#tposts").jqGrid({
url:'/user/' + [% c.user.get("userid") %] + "/entries/all",
datatype: "json",
mtype: "GET",
reloadAfterSubmit:true,
height: 320,
width: 700,
ajaxGridOptions: { contentType: 'application/json' },
ajaxRowOptions: { contentType: 'application/json', type: 'PUT' },
serializeRowData: function (data) { return JSON.stringify(data); },
colNames:['Entry ID','Title', 'Date Created', 'Date Updated', 'Body', 'Published', 'Type'],
colModel:[
{name:'entryid',index:'entryid', width:55},
{name:'title',index:'title', width:80, align:"right",editable:true},
{name:'created_at',index:'created_at', width:90, editable:false },
{name:'updated_at',index:'updated_at', width:100,editable:false},
{name:'body',index:'body', width:150, sortable:false,edittype:"textarea", editoptions:{rows:"10",cols:"30"}, editable:true},
{name:'published',index:'published', width:80, align:"right",editable:true, edittype:"select", editoptions:{value:"1:yes;0:no"}},
{name:'type',index:'type', width:80, align:"right",editable:true, edittype:"select", editoptions:{value:"post:post;page:page"}}
],
rowNum:10,
rowList:[10,20,30],
pager: '#posts',
sortname: 'entryid',
viewrecords: true,
sortorder: "desc",
onSelectRow: function(id){
ajaxGridOptions: { contentType: 'application/json' };
rowid = id;
console.log('id: ' + id + ', edit url:' + '/entry/' + rowid + '/update');
if(id && id!==lastsel){
$('#tposts').restoreRow(lastsel);
lastSel=id;
}
$('#tposts').editRow(id, true, '', '', '/entry/' + rowid + '/update');
},
caption: "Your Posts"
});
var list = $("#tposts");
var selectedRow = list.getGridParam("selrow");
row_data = list.getRowData(selectedRow);
console.log("row data:" + JSON.stringify(row_data));
$("#tposts").jqGrid('navGrid','#posts',{},
{},
{ mtype: "POST", reloadAfterSubmit:true , url: '/entry/new', modal: true },
{ mtype:"POST", reloadAfterSubmit:true , url: '/entry/' + row_data.entryid + "/delete" }, // WHAT THE FUCK DO I DO HERE
{});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment