Skip to content

Instantly share code, notes, and snippets.

@cgillis-aras
Created May 31, 2018 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgillis-aras/1de551dcfd21f8bf0b2bbedd41a66186 to your computer and use it in GitHub Desktop.
Save cgillis-aras/1de551dcfd21f8bf0b2bbedd41a66186 to your computer and use it in GitHub Desktop.
Example of how to filter by a list of IDs in an onSearchDialog event in Aras Innovator
var inn = this.getInnovator();
var ident = inn.newItem("Identity", "get");
var or = ident.newOR();
// Search for our Admin Identities...
var and1 = or.newAND();
and1.setProperty("name", "%Admin");
and1.setPropertyAttribute("name", "condition", "like");
and1.setProperty("is_alias", "1");
// ... and also search for Super User
var and2 = or.newAND();
and2.setProperty("name", "Super User");
and2.setProperty("is_alias", "1");
ident = ident.apply();
// Get an array of IDs that match our criteria
var idArray = [];
for (var i = 0; i < ident.getItemCount(); i++)
{
idArray.push(ident.getItemByIndex(i).getID());
}
// Pass those IDs into our query
inArgs.QryItem.item.setAttribute("idlist", idArray.join(","));
return;
@bansi112
Copy link

bansi112 commented Aug 7, 2023

// EmpListing.js
import React, { useEffect, useState } from "react";
import { Link, useNavigate } from "react-router-dom";

// Dropdown component code from the previous response

const EmpListing = () => {
const [empdata, empdatachange] = useState([]);
const [searchInput, setSearchInput] = useState("");
const navigate = useNavigate();

const LoadDetail = (id) => {
    navigate("/employee/detail/" + id);
};

const LoadEdit = (id) => {
    navigate("/employee/edit/" + id);
};

const Removefunction = async (id) => {
    if (window.confirm('Do you want to remove?')) {
        try {
            await fetch("http://localhost:3004/employee/" + id, {
                method: "DELETE"
            });
            alert('Removed successfully.');
            fetchEmployeeData();
        } catch (error) {
            console.log(error.message);
        }
    }
};

const fetchEmployeeData = async () => {
    try {
        const response = await fetch("http://localhost:3004/employee");
        const data = await response.json();
        empdatachange(data);
    } catch (error) {
        console.log(error.message);
    }
};

useEffect(() => {
    fetchEmployeeData();
}, []);

return (
    <div className="container">
        <div className="card">
            <div className="card-title">
                <h2>Employee Listing</h2>
            </div>
            <div className="card-body">
                <div className="divbtn">
                    <input
                        type="text"
                        placeholder="Search by ID"
                        value={searchInput}
                        onChange={(e) => setSearchInput(e.target.value)}
                        className="form-control"
                        style={{ marginBottom: "10px" }}
                    />
                    <Link to="employee/create" className="btn btn-success">Add New (+)</Link>
                </div>
                <table className="table table-bordered">
                    <thead className="bg-dark text-white">
                        <tr>
                            <th>ID</th>
                            <th>Name</th>
                            <th>Email</th>
                            <th>Phone</th>
                            <th>Country</th>
                            <th>State</th>
                            <th>City</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                    {empdata &&
          empdata
            .filter((item) => item.id.toString().includes(searchInput))
            .map((item) => (
              <tr
                key={item.id}
                style={
                  searchInput && item.id.toString().includes(searchInput)
                    ? { backgroundColor: '#ffc107' }
                    : {}
                }
              >
                                        <td>{item.id}</td>
                                        <td>{item.name}</td>
                                        <td>{item.email}</td>
                                        <td>{item.phone}</td>
                                        <td>{item.country}</td>
                <td>{item.state}</td>
                <td>{item.city}</td>
                                        <td>
                                            <button onClick={() => LoadEdit(item.id)} className="btn btn-success">Edit</button>
                                            <button onClick={() => Removefunction(item.id)} className="btn btn-danger">Remove</button>
                                            <button onClick={() => LoadDetail(item.id)} className="btn btn-primary">Details</button>
                                        </td>
                                    </tr>
                                ))}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
);

}

export default EmpListing;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment