Updating table with Dynatable plugin

后端 未结 1 810
予麋鹿
予麋鹿 2020-12-30 09:47

Im trying dynatable and Im running into an issue. I not sure how to update records from different json files.

My html body:



        
相关标签:
1条回答
  • 2020-12-30 10:06

    See the relevant discussion in this Github issue. The short version is that you want to update your setToItems function so that it

    1. Replaces the original record-set for the dynatable instance.
    2. Calls the process() function of the dynatable instance.

    To do this, let's first cache the dynatable instance object when we first instantiate dynatable (so that we don't have to keep loading it every time the setToItems function is called:

    var dynatable = $('#my-final-table').dynatable({
      dataset: {
        records: json1
      }
    }).data('dynatable');
    

    Now, let's update our function:

    function setToItems (argument) {
      console.log(argument);
      dynatable.settings.dataset.originalRecords = argument;
      dynatable.process();
    }
    

    In the above, we can set the originalRecords to whatever JSON collection we want. But dynatable won't update the table in the DOM until we call process(). This allows us to do multiple interactions at once if we want, such as adding some filters, changing the page, adding sorts, etc. all at once without triggering a DOM update for each individual change unless we tell it to.

    0 讨论(0)
提交回复
热议问题