angular - angular2 jquery UI sortable with model update -


created component having array of datas , doing sortable using jquery ui sortable. pfb component code.

import { component, afterviewinit  } '@angular/core'; declare var $:any;  @component({   selector: 'app-requirement-details',   templateurl: './requirement-details.component.html',   styleurls: ['./requirement-details.component.css'] }) export class requirementdetailscomponent implements afterviewinit  {      private tabledatas = [         {             name:'sameer',             age: '20'         }, {             name:'nithya',             age: '30'         }, {             name:'dinesh',             age: '25'         }, {             name:'ramesh',             age: '40'         }, {             name:'prabhu',             age: '32'         }, {             name:'gopal',             age: '35'         }, {             name:'irshad',             age: '36'         }, {             name:'puhal',             age: '33'         }, {             name:'rajagopal',             age: '38'         }, {             name:'sakthi',             age: '35'         }     ];      constructor() { }       ngafterviewinit () {         let component = this;         $(".rtablebody").sortable({             axis: "y",             cursor: "move",             handle: ".handle",             opacity: 0.6,             helper: function(e, item) {                 console.log("parent-helper: ", item);                 if (!item.hasclass("ui-selected")) {                     //item.addclass("ui-selected");                 }                 // clone selected elements                 var elements = $(".ui-selected").not('.ui-sortable-placeholder').clone();                 console.log("making helper: ", elements);                 // hide selected elements                 item.siblings(".ui-selected").addclass("hidden");                 var helper = $("<div class='rtable' ><div class='rtablebody'></div></div>");                 helper.append(elements);                 console.log("helper: ", helper);                 return helper;             },             start: function(e, ui) {                 var elements = ui.item.siblings(".ui-selected.hidden").not('.ui-sortable-placeholder');                 ui.item.data("items", elements);             },             update: function(e, ui) {                 console.log("receiving: ", ui.item.data("items"));                 $.each(ui.item.data("items"), function(k, v) {                     console.log("appending ", v, " before ", ui.item);                     ui.item.before(v);                 });             },             stop: function(e, ui) {                 ui.item.siblings(".ui-selected").removeclass("hidden");                 $(".ui-selected").removeclass("ui-selected");             }         })         .selectable({             filter: ".rtablerow",             cancel: ".handle"         })      }  } 

and template code below

<div class="rtable">     <div class="rtablerow head">         <div class="rtablehead" style="width:5%;"><strong>si.no</strong></div>         <div class="rtablehead"><span style="font-weight: bold;">name</span></div>         <div class="rtablehead">age</div>     </div>     <div class="rtablebody">         <div class="rtablerow" *ngfor="let data of tabledatas; let = index;">             <div class="rtablecell"><div class="handle"></div>{{i+1}}</div>             <div class="rtablecell">{{data.name}}</div>             <div class="rtablecell">{{data.age}}</div>         </div>     </div> </div> 

table sorting working fine, need along table sorting component model variable should sorted. tried multiple things helped yet.

please give me solution this.

thanks in advance.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -