undefined cell value vs alert/throw error
undefined cell value vs alert/throw error
rkereskenyi
Posts: 2Questions: 0Answers: 0
Hi,
My problem is the following and a bit frustrating to see the alert dialogs. I set up the DataTable columns with the mData parameter for a hierarchical sub-property like mData : "propA.b.c". Then I'm feeding an array of objects to the datatable and some might not have a "propA.b.c" property, or they do have it but the value is undefined (intentionally), so fnGetData returns with undefined, which is perfectly fine and I don't see any other place where it will cause a problem. But for some reason, if the requested cell value is undefined and I dont specifiy a sDefaultContent for that specific column, function _fnGetCellData logs this accident, but, it still renders and works fine after that. So all-in-all having an undefined value here and there seems not to break the functionality, does it?
In my case it is normal that some objects have does not have specific properties occasionally. (think about it as creating an union of all the properties of multiple different objects). I know that setting a sDefaultContent = '' would solve my problem here, but then I would loose the information that the cell is empty because the object had an empty value at that field or that object did not have that field at all. And I don't want to loose that.
I tried a few workarounds with sDefaultContent = _some_value_ but was not able not to loose the 'undefined' value at all.
i just wanted to make sure, that having an undefined value here and there really does not break the functionality, does it?
I could account my real data separately and fake the non-existing values with sDefaultContent = '' for example but than I would need extre logic for all this. And furthermore, DataTable seems to handle this case just fine, but for some reason it gives you a nice alert message, but does not stop the processing of the data, so I assume it's more like a friendly warning than a dealbreaker here.
So what's the solution (besides overwriting the source code not to display alert here) if 'undefined' is an acceptable value for some fields and I don't want to see popup dialogs nor Errors thrown (I can try-catch them externally, but that would stop the whole processing).
Do you guys have a solution for that?
thanks,
r
My problem is the following and a bit frustrating to see the alert dialogs. I set up the DataTable columns with the mData parameter for a hierarchical sub-property like mData : "propA.b.c". Then I'm feeding an array of objects to the datatable and some might not have a "propA.b.c" property, or they do have it but the value is undefined (intentionally), so fnGetData returns with undefined, which is perfectly fine and I don't see any other place where it will cause a problem. But for some reason, if the requested cell value is undefined and I dont specifiy a sDefaultContent for that specific column, function _fnGetCellData logs this accident, but, it still renders and works fine after that. So all-in-all having an undefined value here and there seems not to break the functionality, does it?
In my case it is normal that some objects have does not have specific properties occasionally. (think about it as creating an union of all the properties of multiple different objects). I know that setting a sDefaultContent = '' would solve my problem here, but then I would loose the information that the cell is empty because the object had an empty value at that field or that object did not have that field at all. And I don't want to loose that.
I tried a few workarounds with sDefaultContent = _some_value_ but was not able not to loose the 'undefined' value at all.
i just wanted to make sure, that having an undefined value here and there really does not break the functionality, does it?
I could account my real data separately and fake the non-existing values with sDefaultContent = '' for example but than I would need extre logic for all this. And furthermore, DataTable seems to handle this case just fine, but for some reason it gives you a nice alert message, but does not stop the processing of the data, so I assume it's more like a friendly warning than a dealbreaker here.
So what's the solution (besides overwriting the source code not to display alert here) if 'undefined' is an acceptable value for some fields and I don't want to see popup dialogs nor Errors thrown (I can try-catch them externally, but that would stop the whole processing).
Do you guys have a solution for that?
thanks,
r
This discussion has been closed.
Replies
> I know that setting a sDefaultContent = '' would solve my problem here, but then I would loose the information that the cell is empty because the object had an empty value at that field or that object did not have that field at all. And I don't want to loose that.
I don't quite understand this - how do you lose it. The original data ( fnGetData or _ ) still retains the original value, but the cell is displayed with your sDefaultContent . How would you display null / undefined in a cell? It can't be empty, because that's the same as an empty string with no way to distinguish the two states. That's why sDefaultContent is required - to let you tell DataTables what to do.
Allan
I've tried that. Let's say to avoid the friendly warning I set sDefaultContent = "myDefVal". Then I set fnCreatedCell like (assume myDataTable is a valid reference to my dataTable instance):
[code]
"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
var nData = myDataTable.fnGetData(iRow, iCol);
}
[/code]
Here nData will be 'myDefVal'. So the value I set sDefaultContent will override the undefined and I don't see how could I query it back? What's your proposal?
thank you,
r