Forum
07:04
30/09/2009
Last night (GMT+7) I have tried to load CKEditor as the WYSIWYG editor when I need to add or editing data with form editing features of JqGrid. Maybe someone out there can learn from what I have learnt that night, at least, you do not need to fell headache as much as I do (I am newbie with less experiences with JqGrid ).
NB: I assume the field name that need to edit with CKEditor is 'keterangan'
* we want to use CKEDITOR, then we need to replace it field before form edit shown
*/
function ab_afterShowForm(ids)
{
if( CKEDITOR.instances.keterangan )
{
try {
CKEDITOR.instances.keterangan.destroy();
} catch(e) {
CKEDITOR.remove( 'keterangan' );
}
//CKEDITOR.instances.keterangan = null;
}
CKEDITOR.replace( 'keterangan',
{
height: 80,
toolbar:
[
['Bold','Italic','Underline','Strike','-','Subscript','Superscript']
],
removePlugins : 'maximize,resize,scayt'
});
// JQGrid
// we need to get selected row in case currently we are in Edit Mode
selID = $('#catdnd').getGridParam('selrow'); // get selected row
// I don't know how to get the current mode is, in Editing or Add new?
// then let's find out if
//navigational buttons are hidden for both of it and selID == null <– Add mode ^0^
if( !($('a#pData').is(':hidden') || $('a#nData').is(':hidden') && selID==null))
{ // then it must be edit?
va = $('#catdnd').getRowData(selID);
CKEDITOR.instances.keterangan.setData( va['keterangan'] );
}
};
/**
* CKEDITOR didn't automaticaly replace our 'keterangan' value then it need to set manually
*/
function ab_beforeSubmit(data)
{
data['keterangan'] = CKEDITOR.instances.keterangan.getData();
return [true];
};
/**
* What if currently in edit mode and user click navigational button?
*/
function ab_afterclickPgButtons(whichbutton, formid, rowid)
{
//$('#catdnd').getRowData(rowid);
va = $('#catdnd').getRowData(rowid);
CKEDITOR.instances.keterangan.setData( va['keterangan'] );
//return [true];
}
Then like commonly rules, attach that function into our JqGrid …
$(jqg_ID).jqGrid({
[ snif ... snif ... ]
colModel:
[
[ snif ... snif ... ],
{name:'keterangan',
editable:true,
edittype:"textarea",
editoptions:{size:80,rows:"2",cols:"10"},
editrules:{edithidden:true}},
[ snif ... snif ... ]
],
[ snif .. snif ... ]
}).navGrid('#pagerdnd',
{edit:true,add:true,del:true},
{height:350, width:731,reloadAfterSubmit:false,
afterSubmit: your_after_submit_edit,
afterclickPgButtons: ab_afterclickPgButtons,
beforeSubmit: ab_beforeSubmit,
afterShowForm: ab_afterShowForm
}, // update data
{height:350, width:731,reloadAfterSubmit:false,
afterSubmit: your_after_submit_add,
beforeSubmit: ab_beforeSubmit,
afterShowForm: ab_afterShowForm
}, // insert data
{height:120, width:300,reloadAfterSubmit:false,
afterSubmit: your_after_submit_delete
} // delete data
);
[ snif ... snif ... ]
That's it
(My apologies for bad English)
23:15
Moderators
30/10/2007
Hello,
Thank you very much for this code. I hope it will be a usefull for a lot of people.
Kind Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Most Users Ever Online: 715
Currently Online:
53 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66