I already work a few days at a first glance at the simple task - to implement a custom cell. The task is following: to make a custom cell with a div element with an id (eg "mydiv"
), then to call a function for this div like $('#mydiv').raty({start: cellvaue, readonly:true})
and then, the 3rd subtask - in the edit mode (editGridRow
) I have to change the parameter of raty-function to readonly:false
as it should be possible to change the value.
Firstly, I have worked with formatter. In formatter I defined my div element, and with calling in afterInsertRow my function $('# mydiv').raty({start: cellvalue, readonly: true}). For the overview it worked perfectly. But, in edit modal dialog of editGridRow
the form input text was always rendered, which I do not need here. I need here still only my div element. If I understand correctly, the formatter only modify the values, but still renders form input text.
Then I swithed to edittype: custom
, but it has not help, because these functions are invoked for the first time only in editGridRow.
I am sure that this problem is solvable, the only question is how.
Thanks for any tips.
UPDATE
Thanks to Oleg now I am very close to a functioning implementation of this task. Here I will describe my solution (based on Oleg's advices, or at least on my interpretion of his tips).
The jqGrid is defined with datatype: "json"
.
The custom cell is defined as:
name:'ranking', editable:true, edittype:'custom',formatter:ratingFormatter,
editoptions:{custom_element:ratingFormatter, custom_value:ratingValue}
The mentioned functions are defined as follows:
function ratingFormatter(cellvalue, options, rowObject) {return '<div class="rnk"></div>';};
function ratingValue(elem, operation, value) {return $('#ranking-score').val();};
Then modal edit dialog:
ondblClickRow: function(id) {
jQuery('#grid').jqGrid('editGridRow',id,
{closeOnEscape:true,width:400,
savekey:[true,13],
recreateForm:true,beforeShowForm:initRating
});
The initRating function:
function initRating() {$('#ranking').raty({path:'/img/'})};
And finally the loadComplete event
loadComplete: function (data) {
var ids = jQuery("#grid").getDataIDs();
for(var i=0;i<ids.length;i++){
var rowid = ids[i];
var ranking = data.rows[i].cell[6];
$('#' + rowid +'> td > div.rnk').raty({path:'/img/',start:ranking,readOnly:true});
$('#' + rowid).contextMenu('MenuJqGrid', eventsMenu);
}
}
So many steps for such small thing as rating plugin. Unbelievable. The last unresolved issue is getting the current rating score into initRating function. It means if I go to the editGridRow I do not have already defined rating score. Hmmm.