Is it safe to manually get JSON via Ajax, save it in JS variable, and then use it as data source?

Is it safe to manually get JSON via Ajax, save it in JS variable, and then use it as data source?

Huk256Huk256 Posts: 8Questions: 2Answers: 0

Assuming we have datatable called "oTable", then basically, what I mean is:

  1. Create some js variable - lets call it "datatableSource";
  2. Call Ajax, get data from server, and store it inside that variable.
  3. Then call:

oTable.fnAddData(datatableSource);

  1. And after we change some data, we call:

oTable.fnClearTable();
oTable.fnAddData(datatableSource);

to repopulate the table...

Question is - is something like this safe, compatible with all browsers? Won't it blow up, when server returns too much data?

Thanks in advance for the answer.

Best regards.

Answers

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    Hi,

    Absolutely this will work and it can have a number of advantages in some situations - preprocessing the data for example.

    Obviously the more data you add to the table, the longer the browsers need to process it - IE6 won't handle the addition of a million rows very well for example!

    I would suggest you make sure you have the deferRender option enabled, since it reduces the initial strain on the browser when you give it new data.

    I would also suggest using the new API for 1.10, rather than the old fn* methods. Specifically clear() and rows.add() here.

    Allan

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    Hi,

    Absolutely this will work and it can have a number of advantages in some situations - preprocessing the data for example.

    Obviously the more data you add to the table, the longer the browsers need to process it - IE6 won't handle the addition of a million rows very well for example!

    I would suggest you make sure you have the deferRender option enabled, since it reduces the initial strain on the browser when you give it new data.

    I would also suggest using the new API for 1.10, rather than the old fn* methods. Specifically clear() and rows.add() here.

    Allan

  • Huk256Huk256 Posts: 8Questions: 2Answers: 0

    Thanks for clarification, I was worried that browsers impose some limits for security reasons, but if we're talking about millions of rows, then this is not an issue - my app will newer come close to that ;]

    As for using 1.10... well in any new project I certainly will, but from what I saw, some porting would be required to convert project from 1.9.4 to 1.10, and I fear something would break in the process.

    Best regards.

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    1.10 should be fully backwards compatible, minus infinite scrolling and fnRender (upgrade notes.

    Allan

  • Huk256Huk256 Posts: 8Questions: 2Answers: 0

    Hmmm, I will look into it then, I was scared off by new method names (or rather by the fact name changed, I think they are much better then before ;] ).

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    There is a conversion document available if you want to see the changes. But the old properties will still work.

    Allan

This discussion has been closed.