fnUpdate when using deep property reading for a data source
fnUpdate when using deep property reading for a data source
jamjon3
Posts: 22Questions: 0Answers: 0
When using deep property reading, I tried to use a fnUpdate like this:
[code]
connectionSourceDataTable.fnUpdate(singleObjOfArray, nRow, 0 );
[/code]
I get this error:
DataTables warning (table id = 'connectionSourceTable'): An array passed to fnUpdate must have the same number of columns as the
table in question - in this case 4
Looks like DataTables is still expecting an array as a row for the "fnUpdate" function. My instinct would be to update the underlying data object (in case I need it later for internal evaluations in "fnRowCallback" where I might call something like aData.connection.connectionId and other object properties in that processing).
[code]
connectionSourceDataTable.fnUpdate(singleObjOfArray, nRow, 0 );
[/code]
I get this error:
DataTables warning (table id = 'connectionSourceTable'): An array passed to fnUpdate must have the same number of columns as the
table in question - in this case 4
Looks like DataTables is still expecting an array as a row for the "fnUpdate" function. My instinct would be to update the underlying data object (in case I need it later for internal evaluations in "fnRowCallback" where I might call something like aData.connection.connectionId and other object properties in that processing).
This discussion has been closed.
Replies
The reason I was a bit concerned was that I think that it's going to be quite difficult to implement fully and correctly. Although I suppose it could be that the full object is just replaced and then effectively do an update on each column... That might be best - added to the list...
Regards,
Allan
Hope I'm not being a pain but I will get you one of your Amazon books on my next paycheck (friday, aka. tomorrow). ;-)
BTW: I've been using DataTables extensively in my cimsPR 2.0 app and you deserve contributions!!!
[code]
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
$(nRow).unbind('click')
.click(function (event) {
if(!($(event.target).is('select#connectionsId',nRow))) {
if($(nRow).hasClass('row_selected')) {
$(nRow).removeClass('row_selected');
connectionSourceDiscardSourceButton.button( "option", "disabled", true );
} else {
$(self.connectionSourceDataTable.fnGetNodes( )).each(function() {
$(this).removeClass('row_selected');
});
$(nRow).addClass('row_selected');
connectionSourceDiscardSourceButton.button( "option", "disabled", false );
}
}
})
.find('select#connectionsId')
.change(function() {
var jsonRequest = {
recursionIndex: 10,
source: {
sourceId : aData.sourceId
}
};
if($(this).val() !== '') {
var connectionsId = $(this).val();
$.extend(jsonRequest,{
connection: {
connectionsId: connectionsId
}
});
}
$.ajax({
url: "/cimsPR/ConnectionServlet",
title: 'Assigning connection to source',
data : {
service : "assignConnectionToSource",
json: JSON.stringify(jsonRequest)
},
success: function(assignConnectionToSourceResponse, textStatus, jqXHR) {
// Find the this source in the array and update the values
$.each(connection.sources,function(index, source) {
if(source.sourceId == aData.sourceId) {
connection.sources[index] = assignConnectionToSourceResponse.source;
var isSelected = $(nRow).hasClass('row_selected');
connectionSourceDataTable.fnDeleteRow(nRow);
nRow = connectionSourceDataTable.fnGetNodes(connectionSourceDataTable.fnAddData(assignConnectionToSourceResponse.source)[0]);
if(!isSelected) {
$(nRow).addClass('row_selected');
}
// connectionSourceDataTable.fnUpdate(source, nRow, 0 );
self.storage.connection.sources = connection.sources;
return false;
} else {
return true;
}
});
}
});
});
return nRow;
}
[/code]
Allan
[code]
{
"source": {
"sourceId": 7,
"name": "MANUALENTRY",
"description": "",
"connection": {
"connectionsId": 3,
"hibernateProperties": "hibernate.current_session_context_class\u003djta\r\nhibernate.show_sql\u003dtrue\r\nhibernate.session_factory_name\u003dcims_datawarehousePU_sf\r\nhibernate.dialect\u003dorg.hibernate.dialect.Oracle10gDialect\r\nhibernate.jdbc.fetch_size\u003d2000\r\nhibernate.transaction.manager_lookup_class\u003dorg.hibernate.transaction.SunONETransactionManagerLookup\r\njta.UserTransaction\u003djava:comp/UserTransaction",
"jndi": "jdbc/cims_datawarehouse",
"namedQueries": [
]
}
}
}
[/code]
but is returning this object from a fnGetData
[code]
{
"sourceId": 7,
"name": "MANUALENTRY",
"description": "",
"null": "Unassigned1 - jdbc/cimsPR2 - jdbc/cims_oasis3 - jdbc/cims_datawarehouse4 - jdbc/cims_alumni5 - jdbc/cims_idcards6 - jdbc/cims_nams7 - jdbc/cims_med_banner8 - jdbc/cims_med_alt_banner9 - jdbc/cims_namsdev10 - jdbc/cims_baggageclaim11 - jdbc/cims_gems12 - jdbc/cims_peopleadmin"
}
[/code]
I'm using a "fnRender" to render the selectbox but it looks like the "connection" object is being destroyed and replaced with one named "null" with the results of the fnRender. The effect this is having and returning the select back to the original selected value before the change event occurred. Not sure what's happening but it looks like the previous rendered column before the select drop down change is replacing the connections object.
I'm using your latest nightly. Soooo close!!!! Thanks for your patience with me!!!!
BTW: Here's my fnRender reference for the connections column
[code]
{ "sTitle": "Connection (Re)Assignment","sClass": "SearchColumn","mDataProp": "null","sDefaultContent":"","fnRender":
function(oObj) {
// Build a drop down of Connections
var connectionSelect = "";
if(oObj.aData.connection !== undefined) {
connectionSelect += "Unassigned";
} else {
connectionSelect += "Unassigned";
}
$.each(connection.connections,function(index,conn) {
if((oObj.aData.connection !== undefined)?((oObj.aData.connection.connectionsId === conn.connectionsId)?true:false):false) {
connectionSelect += ["",conn.connectionsId," - ",conn.jndi,""].join("");
} else {
connectionSelect += ["",conn.connectionsId," - ",conn.jndi,""].join("");
}
});
connectionSelect += "";
return connectionSelect;
}
}
[/code]
[code]
"mDataProp": "null"
[/code]
which is setting the data property DataTables is using to the string "null" - not null. null !== "null" :-)
You should have more luck with:
[code]
"mDataProp": null
[/code]
Allan
[code]
{ "sTitle": "Connection (Re)Assignment","sClass": "SearchColumn","mDataProp": "connection","sDefaultContent":"","fnRender": and so on...
[/code]
Gives you the render mapped to the name specified (here I put "connection")
[code]
{"sourceId":7,"name":"MANUALENTRY","description":"","connection":"Unassigned1 - jdbc/cimsPR2 - jdbc/cims_oasis3 - jdbc/
cims_datawarehouse4 - jdbc/cims_alumni5 - jdbc/cims_idcards6 - jdbc/cims_nams7 - jdbc/cims_med_banner8 - jdbc/
cims_med_alt_banner9 - jdbc/cims_namsdev10 - jdbc/cims_baggageclaim11 - jdbc/cims_gems12 - jdbc/cims_peopleadmin"}
[/code]
And, of course, using null instead of "null" (THANKS for catching that) like:
[code]
{ "sTitle": "Connection (Re)Assignment","sClass": "SearchColumn","mDataProp": null,"sDefaultContent":"","fnRender": .. and so on
[/code]
Gives back the unaltered object perfectly like this just as you suggested (thanks for the help on that!)
[code]
{"sourceId":7,"name":"MANUALENTRY","description":"","connection":{"connectionsId":
3,"hibernateProperties":"hibernate.current_session_context_class=jta\r\nhibernate.show_sql=true\r
\nhibernate.session_factory_name=cims_datawarehousePU_sf\r\nhibernate.dialect=org.hibernate.dialect.Oracle10gDialect\r
\nhibernate.jdbc.fetch_size=2000\r
\nhibernate.transaction.manager_lookup_class=org.hibernate.transaction.SunONETransactionManagerLookup\r
\njta.UserTransaction=java:comp/UserTransaction","jndi":"jdbc/cims_datawarehouse","namedQueries":[]}}
[/code]
Not exactly sure how one might make use of that BUT it IS a cool mechanism that could be useful depending on one's circumstances. Of course, since I'm doing serialization/deserialization on the app side, I'm keeping it all true in structures client-side so I can pass objects back and forth but who knows! Thanks again!
Pretty fantastic stuff you've created here!
Good to hear that this is proving to be useful already - I'm using the mDataProp options in some of my own uses of DataTables now as well and finding it very useful! Thanks fir your inout and testing this feature.
Regards,
Allan
My work around is to generate an array of name of each td after initiate the table. and on fnDrawBack I loop through the fnGetNodes().childNodes and look for the one without name attribute then replace each with the values in the array.
I know there must be a better way, i just could not find it :(
[code]
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
var rowNames = [
"col1",
"col2",
"col3"
];
$(nRow).children().each(function(index,nCol) {
$(nCol).attr("name",rowNames[index]);
});
return nRow;
}
[/code]
[code]
"fnInitComplete": function(){
for(i=0; i < this.fnGetNodes(0).childNodes.length; i++)
{
f_name_arr[i] = this.fnGetNodes(0).childNodes[i].getAttribute("name");
}
},
"fnDrawCallback": function(){
for(i=0; i < this.fnGetNodes().length; i++)
{
temp_row = this.fnGetNodes(i);
if(!(temp_row.childNodes(0).getAttribute("name")))
{
for(j=0; j < temp_row.childNodes.length; j++)
{
temp_row.childNodes[j].setAttribute("name",f_name_arr[j]);
}
break;
}
}
fnCreateFilter(this); //refresh filter
}
[/code]