Is it feasible to display the Autocomplete suggestions with column titles?

https://i.sstatic.net/m5faM.png

Is there a way to customize the list in the above example with column headers like Title and duration? I attempted to achieve this using a custom ListBox, but without success. Below is an excerpt from my code:

const PopperMy = function (props: PopperProps) {
    return <Popper {...props} style={{ width: 500 }} placement='bottom-start' />;
};

return (
            <Autocomplete
                filterOptions={(x) => x}
                getOptionLabel={(option: Record<string, unknown>) => `${option.order}, ${option.name}, ${option.email}, ${option.phone}, ${option.location}`}
                renderOption={(props, option: any) => {
                    return (
                        <li {...props} key={option.ID} >
                            Order: {option.order}, Name: {option.name}, Email: {option.email}, Phone: {option.phone}, Location: {option.location}, Status: {option.status}
                        </li>

                    );

                }}
                options={results}
                value={selectedValue}
                clearOnBlur={false}
                freeSolo
                PopperComponent={PopperMy}
                disableClearable={true}
                includeInputInList
                onChange={(ev, newValue) => {
                    setSelectedValue(newValue);
                }}
                onInputChange={(ev, newInputValue) => {
                    setInputValue(newInputValue);
                }}
                renderInput={(params) => (
                    <TextField {...params} />
                )} /> )
                        

Answer №1

To make this customization possible for the popper component, you can create a specialized PopperMy component in your code.

const PopperMy = function (props) {
  const { children, ...rest } = props;
  return (
    <Popper {...rest} placement="bottom-start">
      <Box display="flex" justifyContent="space-between" px="16px">
        <Typography variant="h6">Title</Typography>
        <Typography variant="h6">Year</Typography>
        ........... rest of the titles
      </Box>
      {props.children}
    </Popper>
  );
};

This customized approach should be helpful for achieving the desired functionality. You can view a demonstration of this implementation in action through this example I have prepared - Demo Link

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to apply and remove class from buttons in a React application?

There are a total of 20 buttons and I want to apply the class .active to the button that is clicked, while removing it from any previously active button. For example, if I click on button one, it should become active and if I then click on button two, bu ...

Tips for setting the initial state in React context with useState as the value

Watching a video on YouTube by Jack Herrington titled "Mastering React Context," I was intrigued by his use of useState as a value for the context provider. However, when I attempted to replicate this using TypeScript, I found myself struggling with how to ...

Remove an item from an array and keep it stored efficiently without generating unnecessary waste

I'm interested in finding a high-performance method for removing and storing elements from an array. My goal is to create an object pool that minimizes the need for garbage collection calls. Similar to how .pop() and .unshift() remove elements from a ...

What is the best way to create CSS selectors that target specific devices?

Is there a way to create selectors specific to different devices? I've tried searching on Google for information about it, but I couldn't find anything relevant. ...

A step-by-step guide on activating ListItemButton with React Router v6 Link

Seeking guidance on integrating the functionality of MUI's Mini Variant Drawer example with React Router v6's Link element. The documentation lacks clarity on this aspect, and my attempts to configure it have been unsuccessful despite multiple it ...

Marquee fading with a touch of Twitter-style flair - seamlessly blended

Does anyone know how to create a marquee effect similar to Twitter? I need it to be seamless (no stopping when the loop ends) and to fade at the start and end. Thanks! Edit Okay, I found a somewhat seamless solution here http://jsbin.com/uyawi/3/edit, bu ...

Utilize the same variable within a React functional component across multiple components

Within a React functional component, I am utilizing the following constant: const superHeroPowers = [ { name: 'Superman', status: superManPowerList }, { name: 'Batman', status: batmanPowerList }, { name: 'Wonder Woman&a ...

transform JSON structure into an array

Is it possible to convert an interface class and JSON file into a list or array in order to work on it? For example, extracting the Racename from each object in the JSON file and storing it in a list/array. Here is the interface structure: interface IRunn ...

Send the user back to the homepage without the need to refresh the page

When the user clicks "Okay" in my window.prompt, the code below opens a new tab. Is there a way to direct the user to the home page without opening a new tab? if (window.confirm("Do you really want to leave?")) { window.open("./Tutoria ...

Struggling with the Nivo slider not loading properly?

Check out my personal website. I'm having an issue with my Nivo slider not displaying properly - it just keeps loading. Any ideas on why this is happening and how I can fix it? Below is the CSS I am using: #slider { position:relative; width: ...

What is the best way to manage several asynchronous requests concurrently?

Can anyone recommend some valuable resources or books that explain how to effectively manage multiple asynchronous requests? Consider the code snippet below: Payment.createToken = function(data) { var data = data; apiCall("POST", "api/createToke ...

Issue with ng-selected not functioning properly

I am facing an issue where the ng-selected is assigned as true but the option is not being selected. The following is my controller code: .controller("PendingInvoiceCtrl", function($scope, $location, safeApply, dataService) { var userData = dataServi ...

Mastering route localization in NextJS using next-i18next

Currently, I am in the process of developing a multi-language website using next.JS and the next-i18next package. Progress has been smooth overall, although there is one aspect where I am uncertain about the best approach to take. My goal is to have my sta ...

Using .getJSON and .each in Javascript can sometimes be inconsistent in their functionality

I encountered a perplexing issue that has left me stumped. I am dynamically populating data into an html <select></select>. However, upon refreshing the page, I noticed that sometimes the data loads successfully, but most of the time it does n ...

Having trouble retrieving the response from Jquery ajax with ajaxoptions

Struggling to utilize jQuery effectively. function fetchData(Id) { var ajaxOptions = { url: 'Api/Client/Get?Id=' + id, type: 'GET', dataType: 'json' }; return $.ajax(ajaxOptions).done().fa ...

Does React 16's Portal API serve as a alternative to the Context API?

It appears that the new feature called portals may be able to do a similar job but even better than before. While I am not very familiar with portals, it seems like they could be the latest way to handle updates within nested components. I was aware that ...

Managing URL parameters is a common task in web development. Both jQuery and PHP offer functions to easily

Whenever a link is clicked, I am passing a string through a URL to another page. A PHP while loop creates the original a tag and its href as shown below: <a href=".($row['secondary'] == 'true' ? "secondary_imgs.php?imgId=".$row[&ap ...

Server node experiencing a crash due to 'Error: ETIMEDOUT: connection timed out'

I've encountered an issue while trying to run a node.js server file. Strangely, it has started crashing when I attempt to run it from the terminal. I have not made any changes to the file itself, and other alterations in the system shouldn't affe ...

Having trouble with updating npm or installing npm modules on macOS

npm ERR! Darwin 17.2.0 npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "i" "-g" "npm" npm ERR! node v6.9.2 npm ERR! npm v3.10.9 npm ERR! code MODULE_NOT_FOUND npm ERR! Cannot find module 'realize-package-specifier' npm ERR! npm ERR! If ...

The data type 'string' cannot be assigned to the type 'Message' in NEXT.JS when using TypeScript

Currently, I am undertaking the task of replicating Messenger using Next.Js for practice. Throughout this process, I have integrated type definitions and incorporated "Upstash, Serverless access to the Redis database" as part of my project. I meticulously ...