William Niu
William Niu

Reputation: 15853

How to insert an item in a Selectable control

Is there a "clean" way to insert an item in a jQuery UI Selectable control?

Say, I have the following Selectable:

<div id="selectable">
  <div>Item 1</div>
  <div>Item 2</div>
  <div>Item 3</div>
</div>

I could manually insert a row like:

$('<div>Item 4</div>').addClass('ui-selectee').appendTo($('#selectable'));

While it visually looks correct, is there any events I need to include as well? Is that a clean way to insert an item, or is there a better way?

Upvotes: 4

Views: 2481

Answers (2)

SimonSimCity
SimonSimCity

Reputation: 6572

According to the API you can also just use the option autoRefresh (enabled by default) to extend the list of selectable-elements as you add elements to the DOM-element.

If you have a huge list of elements it's recommended to set autoRefresh to false and call the method refresh manually.

Upvotes: 1

Quincy
Quincy

Reputation: 4433

There's no api for doing it. So I believe your coding is a correct way. You may also try to call the .selectable( "refresh") after addition.

Upvotes: 1

Related Questions