skip to Main Content

I don’t know, I can’t read some JSON file ou put a table which read JSON data (internal or external source)

Does someone have an idea?

Here are my link and script I used

  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.10.1/bootstrap-table.min.css">
  <script src="https://unpkg.com/[email protected]/dist/bootstrap-table.min.js"></script>

Here is my script where I create the table, I use data-URL to load the data from a local JSON file

  <table id="table" data-toggle="table" data-height="460" data-search="true" data-url="data.json">
    <thead>
      <tr>
        <th data-field="id">#</th>
        <th data-field="oeuvre" data-search-formatter="false" data-formatter="nameFormatter">Oeuvres</th>
        <th data-field="type" data-formatter="nameFormatter">Type</th>
        <th data-field="artist" data-formatter="nameFormatter">Artiste</th>
        <th data-field="sheet" data-formatter="nameFormatter">Fiche</th>
      </tr>
    </thead>
  </table>
  <script>
    $table.bootstrapTable('refresh',{data: data})
  })

    function nameFormatter(value) {
      return 'Formatted ' + value
    }
  var $table = $('#table')

  $(function() {
    var data = [
      {"id":1,"oeuvre":"choppe","type":"Ambre","artist":"Etienne","sheet":"<a href="description.html">"}
    ]
    $table.bootstrapTable({data: data})
  })
</script>

I really don’t know why it doesn’t work…

thanks in advance

2

Answers


  1. If you want to load a local json file, try like below.

    function nameFormatter(value) {
              return 'Formatted ' + value
            }
    
            var data = [
              {"id":1,"oeuvre":"choppe","type":"Ambre","artist":"Etienne","sheet":"<a href="description.html">"}
            ]
          $("#table").bootstrapTable({data: data})
    

    And remove data attribute data-url="data.json" from the table.

    You can run the snippet below to see the results.

    function nameFormatter(value) {
          return 'Formatted ' + value
        }
    
        var data = [
          {"id":1,"oeuvre":"choppe","type":"Ambre","artist":"Etienne","sheet":"<a href="description.html">"}
        ]
      $("#table").bootstrapTable({data: data})
    <script
      src="https://code.jquery.com/jquery-3.4.1.min.js"
      integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
      crossorigin="anonymous"></script>
        <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <!-- Latest compiled and minified JavaScript -->
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.10.1/bootstrap-table.min.css">
      <script src="https://unpkg.com/[email protected]/dist/bootstrap-table.min.js"></script>
      
      
      <table id="table" data-toggle="table" data-height="460" data-search="true">
        <thead>
          <tr>
            <th data-field="id">#</th>
            <th data-field="oeuvre" data-search-formatter="false" data-formatter="nameFormatter">Oeuvres</th>
            <th data-field="type" data-formatter="nameFormatter">Type</th>
            <th data-field="artist" data-formatter="nameFormatter">Artiste</th>
            <th data-field="sheet" data-formatter="nameFormatter">Fiche</th>
          </tr>
        </thead>
      </table>

    If you want to load from an external source, your function should contain only the formatter function.

    Try the snippet below to see the results.

    function nameFormatter(value) {
          return 'Formatted ' + value
    }
    <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <!-- Latest compiled and minified JavaScript -->
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.10.1/bootstrap-table.min.css">
    <script src="https://unpkg.com/[email protected]/dist/bootstrap-table.min.js"></script>
    
    <table id="table" data-toggle="table" data-height="460" data-search="true" data-url="https://api.myjson.com/bins/q9n5g">
      <thead>
        <tr>
          <th data-field="id">#</th>
          <th data-field="oeuvre" data-search-formatter="false" data-formatter="nameFormatter">Oeuvres</th>
          <th data-field="type" data-formatter="nameFormatter">Type</th>
          <th data-field="artist" data-formatter="nameFormatter">Artiste</th>
          <th data-field="sheet" data-formatter="nameFormatter">Fiche</th>
        </tr>
      </thead>
    </table>
    Login or Signup to reply.
  2. Remove the data-toggle attribute if you are not loading data from external json file.

    It seems any calls to $(‘#table’).bootstrapTable() are completely ignored when data-toggle is enabled and data is not rendered.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search