0

I'm using iron-data-table loaded with JSON data from iron-ajax. I let the user select multiple lines and click "delete". The list is sent to the backend and is deleted from the database.

<iron-ajax url="/data/ban" last-response="{{users}}" auto></iron-ajax>
         <iron-data-table selection-enabled multi-selection id="banTable"
        items="[[users]]">


handleTap: function() {
      var table = this.$$('#banTable');
      $.ajax({
          type: "POST",
          url: "/ban/remove?_csrf=" + this.token,
          data: JSON.stringify(table.selectedItems),
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          success: function (msg) {
              if (msg) {
                  table.clearCache();
              } else {
                  alert("Cannot update list !");
              }
          }
      });

However on the front-end, the table is not updated. I tried table.clearCache but it does not help.

Any idea on how to proceed ?

user2447161
  • 277
  • 4
  • 12
  • Try not to mix jQuery with Polymer. Use an additional `iron-ajax` to make the request. Also, currently you just make a delete request and don't actually delete the row from the `users` array... – alesc Jan 10 '17 at 16:20
  • Then you would use the `last-response` of this new iron-ajax with the same binding (`{{users}}`) as the first iron-ajax request to update the table ? – user2447161 Jan 11 '17 at 06:43
  • This depends on what that request is returning. If it returns a new list (without the deleted record), then yes, you can bind the `last-response` to `{{users}}` and this will then update the `iron-data-table`. If it only returns a success message, then you can either delete the record from the `users` array or make a new request with your existing `iron-ajax`. – alesc Jan 11 '17 at 08:29

1 Answers1

1

Add some id to your iron-ajax and in your success function call its generateRequest() function:

This.$.myAjax.generateRequest()

This will referesh users array

Shirin Safaeian
  • 950
  • 6
  • 18