I want to do selected listbox items to another listbox, here data will come from database here item is not fixed ,for that reason i need to convert list to multidimensional array. Please check my controller,angular controller and view
In controller:
public class MainDivisionDesignationMapController : Controller
{
private HumanResourceDepartmentDBEntities db = new HumanResourceDepartmentDBEntities();
[HttpGet]
public ActionResult Index()
{
return View();
}
public JsonResult AllListofMainDivisionDesignation()
{
List designation = new List();
var designationgroup = db.HrDesignationGroup.Where(p=>p.Rank==2).ToList();
foreach (var des in designationgroup)
{
var desig = db.HrDesignation.Where(i=> i.DesignationGroupId == des.DesignationGroupId)
.OrderBy(r => r.Rank).ToList();
designation.AddRange(desig);
}
return Json(designation, JsonRequestBehavior.AllowGet);
}
}
angular controller:
var app = angular.module("myMainDivisionDesignationMap", []);
app.controller("MainDivisionDesignationMapCtrl",
function ($scope, $http) {
$scope.selectFaIndex = 0;
$scope.SelectedAvailItems = [];
$scope.SelectedSelectedListItems = [];
$scope.DefaultListItems = [
[]
];
$scope.SelectedListItems = [
[]
];
$scope.AvailableListItems = [
[]
];
AllListofMainDivisionDesignation();
function AllListofMainDivisionDesignation() {
$http.get("MainDivisionDesignationMap/AllListofMainDivisionDesignation").then(function(t) {
$scope.List = t.data;
var inputObj = t.data;
angular.forEach(inputObj, function (value, key) {
this.DefaultListItems.push(key.DesignationName + ':' + value.DesignationName);
});
}); alert($scope.DefaultListItems);
}
angular.copy($scope.DefaultListItems, $scope.AvailableListItems);
alert($scope.AvailableListItems);
$scope.btnRight = function () {
//move selected.
angular.forEach($scope.SelectedAvailItems, function (value, key) {
this.push(value);
}, $scope.SelectedListItems[$scope.selectFaIndex]);
//remove the ones that were moved.
angular.forEach($scope.SelectedAvailItems, function (value, key) {
for (var i = $scope.AvailableListItems[$scope.selectFaIndex].length - 1; i >= 0; i--) {
if ($scope.AvailableListItems[$scope.selectFaIndex][i].DesignationName === value.DesignationName) {
$scope.AvailableListItems[$scope.selectFaIndex].splice(i, 1);
}
}
});
$scope.SelectedAvailItems = [];
};
$scope.btnLeft = function () {
//move selected.
angular.forEach($scope.SelectedSelectedListItems, function (value, key) {
this.push(value);
}, $scope.AvailableListItems[$scope.selectFaIndex]);
//remove the ones that were moved from the source container.
angular.forEach($scope.SelectedSelectedListItems, function (value, key) {
for (var i = $scope.SelectedListItems[$scope.selectFaIndex].length - 1; i >= 0; i--) {
if ($scope.SelectedListItems[$scope.selectFaIndex][i].DesignationName === value.DesignationName) {
$scope.SelectedListItems[$scope.selectFaIndex].splice(i, 1);
}
}
});
$scope.SelectedSelectedListItems = [];
alert($scope.AvailableListItems);
};
});
In View:
@{
ViewBag.Title = "Index";
}
Available Designations | Assigned Designations | ||||
@section scripts{
}
Laxmidhar SahooPosted Dec 8, 2017, 2:15 AM
BKS SahaPosted Dec 7, 2017, 8:47 AM
Laxmidhar SahooPosted Dec 7, 2017, 8:04 AM
BKS SahaPosted Dec 7, 2017, 7:59 AM
Laxmidhar SahooPosted Dec 7, 2017, 7:48 AM