Hi,
I am getting all the Applied Users at once and binding them in a Table1. And I am filtering the users based on the approval and binding them to Table2 by using the below code.
function UserViewModel(){
var self=this;
self.UserName = ko.observable("");
self.ContactNo = ko.observable("");
self.Email = ko.observable("");
self.User_ID = ko.observable("");
self.IsApproved = ko.observable("");
var Users = {
UserName: self.UserName,
ContactNo: self.ContactNo,
Email: self.Email,
User_ID: self.User_ID,
IsApproved: self.IsApproved
};
self.Users = ko.observableArray();
$.ajax({
url: "Home/GetAllUsers",
cache: false,
type: "JSON",
contentType: "application/json; charset=utf-8",
data: {},
success: function(data){
self.ApprovedUsers(data);
}
});
self.ApprovedUsers = ko.observableArray();
self.ApprovedUsers = ko.computed(function(){
return ko.utils.arrayFilter(self.User(),function(item){
return item.IsApproved === 1
});
});
}
$(document).ready(function(){
var viewModel = new UserViewModel();
ko.applyBindings(viewModel);
});
My Requirement is:
When admin approved the user from Table1 I want to remove that user from Table1 and add him to Table2.
My Problem Is:
I am getting the filtered data in observable format, but for that one I cannot able to write the methods either "PUSH" or "REMOVE".
1. How can I get the ObservableArray from the ko.computed.? or
2. Filter the ObservableArray data and return the data in observableArray format. How can I do that.?
Can some body plz help me on this.
Thanks in Advance,
Murali Krishna.
Loading
Jaganathan BantheswaranPosted Dec 18, 2013, 7:46 AM
Please find the modified version of the project.
https://drive.google.com/folderview?id=0B3xV-t63U3T6WE5QUzgycUNQZFE&usp=sharing
Jaganathan BantheswaranPosted Dec 18, 2013, 4:38 AM
Is it possible to upload your sample project? I can work on that for you.
Murali krishna AndePosted Dec 18, 2013, 4:34 AM
I am not getting data when I am using the ko.mapping. So, I changed it to ko.computed.
The code which I posted in the question I am using in my application and I have also tried the code which you replied.
self.ApprovedUsers = ko.computed(function(){
return ko.observableArray(ko.utils.arrayFilter(self.User(),function(item){
return item.IsApproved === 1
}));
});
This is also not working. I am not getting the data even I use the above code. I am developing application using Asp.Net MVC 4 with KnockoutJS.
Thanks,
Murali Krishna.
Jaganathan BantheswaranPosted Dec 18, 2013, 2:52 AM
In your last post, i gave an example with ko.mapping usage. Why are not using that?
Is there any specific reason?
Should use self.Users obseravbleArray to push the users. Not self.ApprovedUsers.
Change self.ApprovedUsers like this,
self.ApprovedUsers = ko.computed(function(){
return ko.observableArray(ko.utils.arrayFilter(self.User(),function(item){
return item.IsApproved === 1
}));
});
I may help you in better way, if you share your code. Else ping me on jaganathan.eswaran[at]gmail[dot]com