Set specific row data

Set specific row data

dathtitdathtit Posts: 7Questions: 0Answers: 0
edited April 2014 in DataTables 1.10
Well i wan to use expression in my table. There is a column for formula and data and a column for id (and a couple of other columns). I check every cells in this col, if it contains formula, call a function to calculate. The formula is simple like this (rowID1 + rowID2 + ....). So it check the rowID and get the value of that row and do the math.
First, i was wondering where should I call the function to calculate the formula : drawCallback, initComplete or anything else.
I was trying to call that in the column render but I cannot access other row data.

Second, I have the problem with the ordering of the data :

[code]
api.column(5).data().each(function (val, index) {
api.cell(index, 5).data(calExpr(val, api, aCol));
});
[/code]

The function calExpr is the formular calculator.

If I understand it well, when I loop throught data in the formula column, calculate it and edit the cell of the row with that index.
But it all messed up. Seem like the order of the column().data() result is in different order.

And in this too. I search the id column for the row need to change and set that row data. But it still messed up.
[code]
api.column(keyCol).data().each(function (val, i) {
if (val == id) {
result = gridAPI.row(i).data()[valCol];
}
});
[/code]


I'm nearly gone mad now. Just gone through the 1.10 api manual but no result. Please give me some advices. Thanks

Replies

  • dathtitdathtit Posts: 7Questions: 0Answers: 0
    edited April 2014
    I figured out the 2nd problem
    [code]
    api.column(5,{order:'original'}).data().each(function (val, index) {
    api.cell(index, 5,{order:'original'}).data(calExpr(val, api, aCol));
    });
    [/code]

    But please some one help me with the first one. And the same issue with sparkline.
    Where should I call the sparkline function.
    Thanks
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Using `initComplete` sounds like a good idea to me, if you are ajax loading the data. If you could link to a test case that would be useful.

    Allan
  • dathtitdathtit Posts: 7Questions: 0Answers: 0
    I tried to create the sparkline in initComplete and it only display in the first page
    http://live.datatables.net/zupifis/8/edit

    It worked with the drawCallback, but it must recreate the sparkline every time I change the page.
This discussion has been closed.