I know there is already an answer for how to check a checkbox with jQuery (Checking a checkbox with jQuery?) however I am struggling more with iterating through a table and comparing two values.
I have a devexpress GridView and TreeList, the GridView contains a list of Usernames, the TreeList contains a list of right names and id's.
What i would like to happen is:
- User Clicks on a Username in table.
- Username is sent to controller and a list of right id's is returned.
- Returned id's are compared to TreeList's right id's
- If (returned right id == treelist right id) Tick the Tree List node checkbox.
I am having trouble with part 3 & 4, I guess JQuery is the best way to go about it but i'm not sure how to do it. I do not want to use Devexpress Client-Side Please see my code below:
JQuery
$(".dxgv").click(function () {
var $row = $(this).closest("tr");
var $tds = $row.find("td:nth-child(1)");
$.each($tds, function () {
var insertText = $(this).text();
$.ajax({
url: '@Url.Action("GetUserRights", "Home")',
data: { 'userLogin': insertText },
type: "post",
cache: false,
success: function (userrightslist) { @*SOMETHING HERE?*@ }
});
});
});
Home Controller
public ActionResult GetUserRights(string userLogin)
{
if (userLogin != null)
{
Manager manager = new Manager();
var data = manager.GetAllRightsRows();
var userlogin = manager.GetUserData(userLogin);
var userrights = userlogin.RightsId.Select(s => new { id = s, text = s });
var rightdetails = manager.GetAllRightsRows();
List<int> userrightslist = new List<int>();
foreach (var u in userrights)
{
foreach (var i in rightdetails)
{
if (u.id == i.Id)
{
var RightID = i.Id;
userrightslist.Add(RightID);
}
}
}
return View("Index", userrightslist);
}
return View("Index");
}
Checkbox Unchecked Example
<span class="dxWeb_edtCheckBoxUnchecked dxICheckBox dxichSys" id="RightsTreeList_R-2_D"><span class="dxKBSW"><input value="U" type="text" readonly="readonly" /></span></span>
Checkbox Checked Example
<span class="dxICheckBox dxichSys dxWeb_edtCheckBoxChecked" id="RightsTreeList_R-2_D"><span class="dxKBSW"><input value="U" type="text" readonly="readonly" /></span></span>
Please don't recommend any changes to the checkbox code as this is created by Devexpress so I cannot make changes.
Home Controller Results Example
userrightslist Count = 117 System.Collections.Generic.List<int>
[0] 1 int
[1] 2 int
[2] 3 int
[3] 5 int
[4] 6 int
[5] 686 int
[6] 7 int
Thanks and please let me know if you need any more information etc.
Aucun commentaire:
Enregistrer un commentaire