---
metadata:
  - name: generator
    content: Diplodoc Platform v5.39.1
alternate:
  - https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/examples/cases/custom_search_results.md
  - https://yandex.com/dev/jsapi-v2-1/doc/ru/v2-1/examples/cases/custom_search_results.md
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/dev/jsapi-v2-1/doc/en/llms.txt

# Custom display for search results

<iframe id="LIVE-EXAMPLE" style="width:100%;height: 400px;border-radius: 8px;border: 1px solid rgba(92, 94, 102, 0.14);" frameBorder="0" src="https://yastatic.net/s3/front-maps-static/maps-front-jsapi-v2-1/examples/2/out/s3-cases/en/custom_search_results/index.html" allow="fullscreen"></iframe>

<a target="_blank" rel="noopener noreferrer" style="display: inline-block;margin-top: 10px;cursor: pointer;border-radius: 4px;padding: 9px 12px;background: #151515;color: white;text-decoration: none;font-weight: 500" href="https://codesandbox.io/p/sandbox/kdm3y7?file=index.html">Open in CodeSandbox</a>

<div id="references">
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ready">ready</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Map">Map</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/map.GeoObjects">map.GeoObjects</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/GeoObjectCollection">GeoObjectCollection</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/control.SearchControl">control.SearchControl</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/templateLayoutFactory">templateLayoutFactory</a>

</div>
<p>
    This example shows how to set a custom view for search results.
</p>
<p>
    The selected results are added to the <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/GeoObjectCollection">GeoObjectCollection</a> collection, where the "click" event is listened for. When a found object
    is clicked, its placemark turns red.
</p>
<p>
    In the same way, the collection's objects have a custom layout set for the popup hint.
</p>

{% list tabs %}

-   index.html

    ```html
    <!DOCTYPE html>
    <html>
        <head>
            <title>Examples. Setting a custom display for search results</title>
            <meta
                http-equiv="Content-Type"
                content="text/html; charset=UTF-8"
            />
            <!--
            Set your own API-key. Testing key is not valid for other web-sites and services.
            Get your API-key on the Developer Dashboard: https://developer.tech.yandex.ru/keys/
        -->
            
            
            
        </head>
        <body>
            <div id="map"></div>
        </body>
    </html>
    ```

-   custom_search_results.js

    ```js
    ymaps.ready(function () {
        var myMap = new ymaps.Map("map", {
                center: [59.22, 39.89],
                zoom: 12,
                controls: [],
            }),
            // Creating an instance of the ymaps.control.SearchControl class.
            mySearchControl = new ymaps.control.SearchControl({
                options: {
                    noPlacemark: true,
                },
            }),
            // The search results will be placed in the collection.
            mySearchResults = new ymaps.GeoObjectCollection(null, {
                hintContentLayout:
                    ymaps.templateLayoutFactory.createClass(
                        "$[properties.name]"
                    ),
            });
        myMap.controls.add(mySearchControl);
        myMap.geoObjects.add(mySearchResults);
        // When the found object is clicked, the placemark turns red.
        mySearchResults.events.add("click", function (e) {
            e.get("target").options.set("preset", "islands#redIcon");
        });
        // Putting the selected result in the collection.
        mySearchControl.events
            .add("resultselect", function (e) {
                var index = e.get("index");
                mySearchControl.getResult(index).then(function (res) {
                    mySearchResults.add(res);
                });
            })
            .add("submit", function () {
                mySearchResults.removeAll();
            });
    });
    ```

{% endlist %}
