Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8349463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:00:20+00:00 2026-06-09T08:00:20+00:00

The subject is a little confusing, but here is what I’m trying to do:

  • 0

The subject is a little confusing, but here is what I’m trying to do:

I have created a KnockoutJS custom binding to display a grid on my page. This works well, I followed the SimpleGrid model on the site. However, some of my fields are dates, booleans, etc. I would like to use a custom binding to transform a date using the time ago plugin, etc. Before I built the grid I would simply assign the custom binding in the grid. Now that I am using a “reusable” grid binding I want to be able to pass in (as part of my column definitions) a list of bindings and values to assign in the template for the header and cells of my grid.

Here’s the HTML in my page:

<div data-bind="grid: grid" />

Here’s the HTML Page View Model:

 var tenantsViewModel = {
    navigateDetails: function (tenant) {
        document.location = '/Tenants/Details/' + tenant.TenantId;
    },
    navigateDomain: function (tenant) {
        window.open("http://" + tenant.Domain);
    },
    grid: new my.grid({
        resource: "system/tenants",
        columns: [
          { display: "Tenant", value: "Name", isLink: true },
          { display: "Enabled", value: "IsEnabled", isLink: false },
          { display: "Tenant Since", value: "CreatedOn", isLink: false },
          { display: "Domain", value: "Domain", isLink: true }
      ]
    })
};
tenantsViewModel.grid.update();
ko.applyBindings(tenantsViewModel);

Here’s my custom grid binding and template:

// Object
my.grid = function (config) {
    var self = this;
    self.data = ko.observableArray([]);
    self.columns = config.columns;
    var resource = config.resource;

    my.grid.prototype.update = function () {
        // A Wrapper for $.ajax()/JSONP
        my.get(resource, function (data) {
            self.data(data);
        });
    };
};

// Templates
var templateEngine = new ko.nativeTemplateEngine();

templateEngine.addTemplate = function (templateName, templateMarkup) {
    document.write("<script type=\"text/html\" id='" + templateName + "'>" + templateMarkup + "<" + "/script>");
};

templateEngine.addTemplate("merlin_grid", "\
                <table class=\"data\">\
                    <thead>\
                        <tr data-bind=\"foreach: columns\">\
                           <th data-bind=\"text: display\"></th>\
                        </tr>\
                    </thead>\
                    <tbody data-bind=\"foreach: data\">\
                       <tr data-bind=\"foreach: $parent.columns\">\
                           <td data-bind=\"css: { link: isLink },text: typeof value == 'function' ? value($parent) : $parent[value] \"></td>\
                        </tr>\
                    </tbody>\
                </table>");

// Grid: Convert element into a full blown grid component
ko.bindingHandlers.grid = {
    init: function () {
        return { controlsDescendantBindings: true };
    },
    update: function (element, viewModelAccessor, allBindingsAccessor) {
        var viewModel = viewModelAccessor(), allBindings = allBindingsAccessor();

        while (element.firstChild)
            ko.removeNode(element.firstChild);

        var gridTemplateName = allBindings.gridTemplate || "merlin_grid";

        var gridContainer = element.appendChild(document.createElement("DIV"));
        ko.renderTemplate(gridTemplateName, viewModel, { templateEngine: templateEngine }, gridContainer, "replaceNode");
    }
};

Is there an easy way to do this?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:00:23+00:00Added an answer on June 9, 2026 at 8:00 am

    I was unable to get this to work. I’ve got a question out to the KnockoutJS user group as well. If they ever respond I’ll post the result here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have little confusion. I am trying to update JTable, but the updates are
I have seen several posts on the subject, but seems like there is little
Well, the subject says it all but I will explain a little further. I
The question maybe a little confusing, but it's hard to make clear this question
I know the subject might be a little strange, but I wasn't sure how
I need a little help on this subject. I have a Web application written
I have done a little googling but not found too much info on the
The subject says it all. Trying to see if I can't change that loading
Sorry for unclear subject but i really don't understand where problem. I use a
Sorry for the subject line, but I wasn't sure how exactly to phrase it.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.