Populate BootstrapTable x-editable select box based on another column

user2242044

I have a BootstrapTable select box. I know you can use a function to populate the values in the select box. I'd like that function to change which array it provides based on the value of a second column (called Text_example).

So in my example, if Text_example for that row is 1, the select box should have the following data: [{1:1}]. if Text_example for that row is 2, the select box should have the following data: [{2:2}]

I think my problem is that I don't know how to pass just the row's data to the function get_values as my method seems not to be working.

Full Fiddle: http://jsfiddle.net/goxe6ehg/

var data = [{"Text_example": 1},{"Text_example": 2}];

function get_values(data) {
    if (data['Text_Example'] === 1) {
    return [{1:1}];
  }
  else {
    return [{2: 2}]
  }

}

$('#table').bootstrapTable({
  columns: [
   {
      field: 'Select_example',
      title: 'Select_example',
      editable: {
        type: 'select',
        source:  get_values($('#table').bootstrapTable('getData'))
      }
    },
    {
      field: 'Text_example',
      title: 'Text_example'
    }
  ],
  data: data
});

EDIT: I over-simplified my example. Rather than having a static field for text_example I need it to be a select box, where the value for select_example changes based on what the user has selected in text_example.

Updated JSFiddle: http://jsfiddle.net/4wwv18Lq/4/

karthick

You can use the oninit handler on the bootstraptable library.And add the editables by iterating through the data object.

var data = [{"Text_example": 1},{"Text_example": 2}];

$('#table').on('editable-init.bs.table', function(e){
    var $els =  $('#table').find('.editable');
     $els.each(function(index,value){
            $(this).editable('option', 'source', data[index])
     });

});
$('#table').bootstrapTable({
  columns: [
   {
      field: 'Select_example',
      title: 'Select_example',
      editable: {
        type: 'select'
      }
    },
    {
      field: 'Text_example',
      title: 'Text_example'
    }
  ],
  data: data
});

JSfiddle link http://jsfiddle.net/km10z2xe/

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

how to convert to an editable select box?

分類Dev

Select value of a column based on another column min(date) with Bigquery

分類Dev

Select distinct values from a column based on highest value in another column

分類Dev

Select MIN, MAX Corresponding column based on another column values

分類Dev

How to populate or update column value in an excel sheet based on data values in another reference column

分類Dev

SQL - Get column value based on another column's average between select rows

分類Dev

Referencing a column in a SELECT from another column in that SELECT

分類Dev

Auto populate HTML Select box with years past and future

分類Dev

pandas groupby with condition on one column to populate another column

分類Dev

I want to select two different columns from two tables based on another column by SQL

分類Dev

Pushing data into a select based on the input of another select

分類Dev

Populate Combo Box with only results that start with selected items first character from another combo box

分類Dev

Autofill column of an Excel table based on another column

分類Dev

color a column based on the values of another column with formattable

分類Dev

specifying a new column based on the criteria in another column

分類Dev

Pandas: Multiply a column based on contents of another column

分類Dev

Categorise column based upon another column values

分類Dev

Assign values in pandas column based on another column

分類Dev

Populating a column based on values in another column - pandas

分類Dev

Updating a column based on another column + interval

分類Dev

Mandatory column based on the value of another column

分類Dev

select a column value that matches with a value of another column

分類Dev

populate values from another data frame based on predefined set of columns

分類Dev

How to auto populate form options based on a column in the attached spreadsheet

分類Dev

Editable Cells in a Column with an arrayformula

分類Dev

Select new range based on another sheets selection

分類Dev

Pandas: aggregate based on filter on another column

分類Dev

Query table based on the value of another tables column

分類Dev

Pandas Conditional Shift Based On Another Column

Related 関連記事

  1. 1

    how to convert to an editable select box?

  2. 2

    Select value of a column based on another column min(date) with Bigquery

  3. 3

    Select distinct values from a column based on highest value in another column

  4. 4

    Select MIN, MAX Corresponding column based on another column values

  5. 5

    How to populate or update column value in an excel sheet based on data values in another reference column

  6. 6

    SQL - Get column value based on another column's average between select rows

  7. 7

    Referencing a column in a SELECT from another column in that SELECT

  8. 8

    Auto populate HTML Select box with years past and future

  9. 9

    pandas groupby with condition on one column to populate another column

  10. 10

    I want to select two different columns from two tables based on another column by SQL

  11. 11

    Pushing data into a select based on the input of another select

  12. 12

    Populate Combo Box with only results that start with selected items first character from another combo box

  13. 13

    Autofill column of an Excel table based on another column

  14. 14

    color a column based on the values of another column with formattable

  15. 15

    specifying a new column based on the criteria in another column

  16. 16

    Pandas: Multiply a column based on contents of another column

  17. 17

    Categorise column based upon another column values

  18. 18

    Assign values in pandas column based on another column

  19. 19

    Populating a column based on values in another column - pandas

  20. 20

    Updating a column based on another column + interval

  21. 21

    Mandatory column based on the value of another column

  22. 22

    select a column value that matches with a value of another column

  23. 23

    populate values from another data frame based on predefined set of columns

  24. 24

    How to auto populate form options based on a column in the attached spreadsheet

  25. 25

    Editable Cells in a Column with an arrayformula

  26. 26

    Select new range based on another sheets selection

  27. 27

    Pandas: aggregate based on filter on another column

  28. 28

    Query table based on the value of another tables column

  29. 29

    Pandas Conditional Shift Based On Another Column

ホットタグ

アーカイブ