Hi Team
The coding is working, now the problem is to find a way when and after filter search. Want to take the result to pass it to the text field from the form using ajax. Below is my current logic.
// ajax call
JavaScript
$(document).ready(function () {
// Function to handle search button click event
$('#searchButton').on('click', function () {
var searchTerm = $('#searchInput').val().trim();
if (searchTerm !== '') {
// Send an AJAX request to the controller action to search for users
$.ajax({
url: '@Url.Action("SearchUsers", "Home")',
type: 'POST',
dataType: 'json',
data: { searchTerm: searchTerm },
success: function (data) {
// Clear previous search results
$('#userTable tbody').empty();
// Iterate through the retrieved user details and append them to the table
$.each(data, function (index, user) {
var row = '' +
'' + user.DisplayName + '' +
'' + user.Email + '' +
'' + user.Title + '' +
'' + user.Department + '' +
'' + user.Presence + '' +
'' + user.WorkPhone + '' +
'' + user.Location + '' +
'';
$('#userTable tbody').append(row);
});
// Show the modal with search results
$('#checkDetailsModal').modal('show');
},
error: function (jqXHR, textStatus, errorThrown) {
// Handle error if any
console.error('Error:', textStatus, errorThrown);
}
});
}
});
// Function to handle OK button click event
$('#okButton').on('click', function () {
// Get the selected user's display name and set it in the Auditor text field
var selectedUserDisplayName = $('#userTable tbody tr.selected td:first').text();
$('#auditor').val(selectedUserDisplayName);
// Close the modal
$('#checkDetailsModal').modal('hide');
});
});
OK
Cancel// form
CSS
@Html.LabelFor(model => model.Auditor, htmlAttributes: new { @class = "col-md-4 col-form-label text-md-right" })
.table-responsive {
overflow-x: auto;
}
Select People and Groups
×
Search
.light-grey-list li {
background-color: #808080; /* Dark Grey color */
padding: 5px;
}
All Users0
Active Directory0
Organization0
Details
Display Name
E-mail Address
Title
Department
Presence
Work Phone
Location
Jithu ThomasRank #437 · 5.7K reputationPosted Mar 4, 2024, 2:26 AM EST
$(document).ready(function () { // ... (your existing code) // Function to handle OK button click event $('#okButton').on('click', function () { // Get the selected user's display name and set it in the Auditor text field var selectedUserDisplayName = $('#userTable tbody tr.selected td:first').text(); $('#auditor').val(selectedUserDisplayName); // Close the modal $('#checkDetailsModal').modal('hide'); // Clear the selected class from the table rows $('#userTable tbody tr').removeClass('selected'); }); });In this updated code:
var selectedUserDisplayName = $('#userTable tbody tr.selected td:first').text();retrieves the display name of the selected user from the first column of the selected table row.$('#auditor').val(selectedUserDisplayName);sets the value of the#auditortext field with the selected user's display name.$('#userTable tbody tr').removeClass('selected');removes the 'selected' class from all table rows, ensuring that the next time the modal is opened, there are no previously selected rows.Make sure to include these changes in your existing JavaScript code.
Tuhin PaulRank #7 · 71.9K reputationPosted Mar 9, 2024, 3:24 PM EST
$(document).ready(function () { // Function to handle OK button click event $('#okButton').on('click', function () { // Retrieve the selected user's display name var selectedUserDisplayName = getSelectedUserDisplayName(); // Set the selected user's display name in the Auditor text field $('#auditor').val(selectedUserDisplayName); // Close the modal $('#checkDetailsModal').modal('hide'); // Clear the selected class from the table rows $('#userTable tbody tr').removeClass('selected'); }); // Function to retrieve the selected user's display name function getSelectedUserDisplayName() { var selectedUserDisplayName = ''; // Check if any user is selected var selectedRow = $('#userTable tbody tr.selected'); if (selectedRow.length > 0) { // Retrieve the display name from the first column of the selected row selectedUserDisplayName = selectedRow.find('td:eq(0)').text(); } else { // Handle case when no user is selected console.error('No user selected.'); } return selectedUserDisplayName; } });Instead of selecting the first column of the selected table row using
$('#userTable tbody tr.selected td:first'), you can optimize it by directly targeting the first column with$('#userTable tbody tr.selected td:eq(0)').