Inline Select Show Current Value on Double-Click?
Inline Select Show Current Value on Double-Click?
tcbeaton
Posts: 16Questions: 0Answers: 0
I'm using a drop-down select with inline editing. Prior to double-clicking the editable cell shows the current value, once I double-click, the select appears but it is defaulting to the first item in the list. Is it possible to either:
(a) have the drop-down default to the matching item in the select list that the cell contains, or
(b) dynamically replace the first element of the select list with the current item value?
Thanks,
--Tom
[code]
$(document).ready(function() {
var oTable = $('#mtTable').dataTable( {
.
. (omitted for brevity)
.
"fnDrawCallback": function ( oSettings ) {
var that = this;
/* Need to redo the counters if filtered or sorted */
if ( oSettings.bSorted || oSettings.bFiltered )
{
this.\$('td:first-child', {"filter":"applied"}).each( function (i) {
that.fnUpdate( i+1, this.parentNode, 0, false, false );
} );
setTimeout( function() {
\$(".editCat").editable("process_category_change.cgi?callletters=XXXX", {
"callback":function(sValue,y) {
var aPos = oTable.fnGetPosition(this);
oTable.fnUpdate(sValue,aPos[0],aPos[1]);
},
tooltip: "Double-click to edit...",
data : "{'-1':'(clr)','0':' ','1':'A','2':'B','3':'C'}",
type : "select",
event : "dblclick",
onblur : "submit",
style : "inherit"
});
},0);
}
}
} );
} );
[/code]
(a) have the drop-down default to the matching item in the select list that the cell contains, or
(b) dynamically replace the first element of the select list with the current item value?
Thanks,
--Tom
[code]
$(document).ready(function() {
var oTable = $('#mtTable').dataTable( {
.
. (omitted for brevity)
.
"fnDrawCallback": function ( oSettings ) {
var that = this;
/* Need to redo the counters if filtered or sorted */
if ( oSettings.bSorted || oSettings.bFiltered )
{
this.\$('td:first-child', {"filter":"applied"}).each( function (i) {
that.fnUpdate( i+1, this.parentNode, 0, false, false );
} );
setTimeout( function() {
\$(".editCat").editable("process_category_change.cgi?callletters=XXXX", {
"callback":function(sValue,y) {
var aPos = oTable.fnGetPosition(this);
oTable.fnUpdate(sValue,aPos[0],aPos[1]);
},
tooltip: "Double-click to edit...",
data : "{'-1':'(clr)','0':' ','1':'A','2':'B','3':'C'}",
type : "select",
event : "dblclick",
onblur : "submit",
style : "inherit"
});
},0);
}
}
} );
} );
[/code]
This discussion has been closed.
Replies
[code]
data : function (value,settings) { // this code "selects" the current value in the drop-down list
return "{'-1':'(clr)','0':' ','1':'A','2':'B','3':'C','selected':'"+jsCategories[value.trim()]+"'}";
},
[/code]
Where "jsCategories" is an associative array, to map the "value" back to the numeric value (i.e., 'B' back to 2).
this looks like this could well help me with a problem I'm having !!
Where do you declare oSettings ???
Also can you explain the purpose of assigning the table initialization to a variable, ie:
var oTable = $('#mtTable').dataTable( {
as the standard documentation example shows the declaration as a stand alone function.
I'm afraid my answers aren't going to be very helpful... It's been a long time since I've been working on the project that uses DataTables.
1) oSettings is set automatically based on the rest of the table settings and is passed into the fnDrawCallback function, you may also be able to explicitly set values in the area that I omitted above (search the DataTables website for oSettings, there were lots of examples of just about everything when I was learning about it for my project).
2) The other question regarding assigning the table initialization to a variable... It was the way it was done in one of the examples I found to accomplish the task I needed.
Sorry I couldn't really be more help, but I figured I'd respond so you didn't think I was ignoring you.
That's how you access the API. For example: http://datatables.net/release-datatables/examples/api/multi_filter.html
Allan