KingTable icon indicating copy to clipboard operation
KingTable copied to clipboard

Trying to extend KingTable.Schemas.DefaultByType (says _ is not defined)

Open masterfulEJ opened this issue 6 years ago • 1 comments

So in a new template which I've mostly re-used the rhtml-colors.html template, I'm giving in numbers which are percent type. Unfortunately, I'm not very good at javascript, but I'm getting the error of not defined "_" from console, when I added the extension script. Could you help me understand.

<script>
  (
    function () {
      _.extend(KingTable.Schemas.DefaultByType, {
        percent: function (columnSchema, objSchema) {
          return {
            format: function (value) {
              // TODO: implement your formatting logic
              // (for thousands separator, decimal separators) - culture dependent
              return value * 100 + " %";
            }
          };
        }
      });
      var table = window.table = new KingTable({
        id: "data-table",
        url: "/api/mydata",
        caption: "KingTable - portfolio demo with server side pagination (paginated set in memory)",
        element: document.getElementById("main"),
        columns: {
          {{ instruct|safe }}
        }
      });

      table.render().then(function () {
        console.log("ok :)");
      }, function () {
        console.log("noo :(");
      });
    }
  )();

masterfulEJ avatar Jan 25 '19 01:01 masterfulEJ

Hi @masterfulEJ, In my code, the variable '_' is imported, that's why it works in my source code but not in your context.

You need to import the same module, if you are using the new EcmaScript with transpilation. Otherwise, you need a global variable with compatible methods, such as Lodash library.

I am intentionally calling this variable _ because it contains general purpose functions, similar to what you can find in Lodash.

RobertoPrevato avatar Jan 25 '19 08:01 RobertoPrevato