AddData and DeleteData

AddData and DeleteData

mishaBymishaBy Posts: 3Questions: 0Answers: 0
edited May 2009 in General
first of all, excuse for my English. I have read all topics with 'DeleteData', but I have a problem. I have 2 tables, and from one I post data to another, for example I have a row(from table 1) and post it by
fnClickAddRow=function(data)
{
oTableDataRemarksConclusionList.fnAddData([
data['date'],
data['problem'],
data['info'],
data['status']]
);
}
to another table
then I have in my second table a link to delete this row from the second table:
var anSelected = fnGetSelected(oTableDataRemarksConclusionList,remark_id,key);
var iRow = oTableDataRemarksConclusionList.fnGetPosition(anSelected[0]);
oTableDataRemarksConclusionList.fnDeleteRow(iRow);
It's almost the same as in 'Api Delete', but if I want to add the same row(that I have already deleted) from the first table, it's ok, but this row in the second table has Index, the same, as the row I have already deleted, and if I want to delete this row again(the second time) , it's not ok.
I think that the problem in cashe, so if I do
oSettings = oTableDataRemarksConclusionList.fnSettings();
var iLen = oSettings.aoData[iRow]._aData;
alert(iLen);
I have the data from my deleted row. so, how I can delete this row finally from the Dom? or how I can add row, then delete this row, and again add this row, but with anothr Index?

Replies

  • allanallan Posts: 63,578Questions: 1Answers: 10,483 Site admin
    Hmm - it's a good one. Could you post a link to an example? It's quite hard to follow just from the description - but I suspect you might be running into one of two possible issues:

    1. When you call fnDeleteRow() it doesn't actually delete the data from aoData - it just removes it from aiDisplay and aiDisplayMaster (internal DataTables variables) and as such it is possible that something is matching there. To over come this it might be best to set the deleted row (in aoData) to null. I'm thinking about making this the default action - but not quite decided yet!).

    2. Might fnGetSelected() be caching something? How does this function work?

    Thanks,
    Allan
  • mishaBymishaBy Posts: 3Questions: 0Answers: 0
    unfortunately, It's a part of a big closed system, but in the evening, or at night I try to transfer this thing on my hosting, and then I'll give you a link.

    1.yes,I think it is the problem. but, when I add and delete the row first time, it removes it from aiDisplay and aiDisplayMaster, but not from aoData. ant then, when I add and delete the same row, it doesn't remove ???? from display, and then if I want to add and delete the sam? row again, it makes copies of this row in aiDisplay.
    so, I think the solution is to call fnDeleteRow() and delete this row from aoData the same time.
    so,
    var anSelected = fnGetSelected(oTableDataRemarksConclusionList,remark_id,key);
    var iRow = oTableDataRemarksConclusionList.fnGetPosition(anSelected[0]);
    oTableDataRemarksConclusionList.fnDeleteRow(iRow);
    oSettings = oTableDataRemarksConclusionList.fnSettings();
    oSettings.aoData[iRow]._aData=null; ?! is it right?
    alert(oTableDataRemarksConclusionList.fnGetData());
    because when I do it firstly It's all right and there is no this row in in aiDisplay. and when I call alert(oTableDataRemarksConclusionList.fnGetData());, it doen't show my row.
    but the second time I add this row, and when I delete, there is an error: (oSettings.aoData[iAODataIndex]._aData is null) and it calls an exception

    2.fnGetSelected=function(oTableLocal,remark_id,key)
    {
    var aReturn = new Array();
    var aTrs = oTableLocal.fnGetNodes();
    for ( var i=0 ; i
  • mishaBymishaBy Posts: 3Questions: 0Answers: 0
    and about ypur decision to make it the default action, I think it gives new possibilities for developers to play with this tables dynamically. and I wish to express gratitude for this script. I have used many tablesorters and so on, but DataTables I really enjoy
  • allanallan Posts: 63,578Questions: 1Answers: 10,483 Site admin
    Phew - quite a complicated one to follow this. I would set the whole aoData[iRow] object to null (rather than just _aData). The issue is certainly that the index you are giving for second delete row call is invalid - so it's a case of figuring out why that is. Are you able to post a cut down example?

    Regarding making the delete row function set aoData[i] to null, the reason not to do this is that the current method provides a lot of flexibility with regard to restoring rows if the developer wanted to do this for whatever application - plus the majority of interactions with the core data should be with aiDisplay and aiDisplayMaster and the indexes that they point to in aoData.

    Allan
This discussion has been closed.