--- title: Adapters and Decorators taxonomy: category: docs --- Starting in version 4.0, Select2 uses the [Adapter pattern](https://en.wikipedia.org/wiki/Adapter_pattern) as a powerful means of extending its features and behavior. Most of the built-in features, such as those described in the previous chapters, are implemented via one of the [built-in adapters](/default-adapters). You may further extend the functionality of Select2 by implementing your own adapters. ## Adapter interfaces All custom adapters must implement the methods described by the `Adapter` interface. In addition, adapters that override the default `selectionAdapter` and `dataAdapter` behavior must implement the additional methods described by the corresponding `SelectionAdapter` and `DataAdapter` interfaces. ### `Adapter` All adapters must implement the `Adapter` interface, which Select2 uses to render DOM elements for the adapter and bind any internal events: ``` // The basic HTML that should be rendered by Select2. A jQuery or DOM element // should be returned, which will automatically be placed by Select2 within the // DOM. // // @returns A jQuery or DOM element that contains any elements that must be // rendered by Select2. Adapter.render = function () { return $jq; }; // Bind to any Select2 or DOM events. // // @param container The Select2 object that is bound to the jQuery element. You // can listen to Select2 events with `on` and trigger Select2 events using the // `trigger` method. // @param $container The jQuery DOM node that all default adapters will be // rendered within. Adapter.bind = function (container, $container) { }; // Position the DOM element within the Select2 DOM container, or in another // place. This allows adapters to be located outside of the Select2 DOM, // such as at the end of the document or in a specific place within the Select2 // DOM node. // // Note: This method is not called on data adapters. // // @param $rendered The rendered DOM element that was returned from the call to // `render`. This may have been modified by Select2, but the root element // will always be the same. // @param $defaultContainer The default container that Select2 will typically // place the rendered DOM element within. For most adapters, this is the // Select2 DOM element. Adapter.position = function ($rendered, $defaultContainer) { }; // Destroy any events or DOM elements that have been created. // This is called when `select2("destroy")` is called on an element. Adapter.destroy = function () { }; ``` ### `SelectionAdapter` The selection is what is shown to the user as a replacement of the standard `