Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
masterfulEJ opened this issue Jan 25, 2019 · 1 comment

Comments

@masterfulEJ
Copy link

masterfulEJ commented Jan 25, 2019

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 :(");
      });
    }
  )();
@RobertoPrevato
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants