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 8652099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:13:46+00:00 2026-06-12T14:13:46+00:00

I am using knockout.js lib to bind data. Let’s I have next example JSFiddle

  • 0

I am using knockout.js lib to bind data.
Let’s I have next example
JSFiddle Example

I have table with data. Table have columns order –

Name – LastName – Middlename – Age
and i have 4 functions

var namePosition = function()

var lastnamePosition = function()

var middlenamePosition = function()

var agePosition = function()  

i want bind order of columns in table to values that are returned by this functions.
For example
namePosition returns 4
lastnamePosition returns 2
middlenamePosition returns 1
agePosition returns 3
then table shouls have next column order –
Middlename – LastName – Age – Name.
Have you any ideas, how can I do it? (using knockout or jquery)

  • 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-12T14:13:47+00:00Added an answer on June 12, 2026 at 2:13 pm

    What Diodeus said is a good way to go. You can generate order array using those functions:

    var order = [];
    order[namePosition()] = "name";
    order[lastnamePosition()] = "last";
    order[middlenamePosition()] = "middle";
    order[agePosition()] = "age";
    
    // order===["middle", "last", "age", "name"]
    

    And then set order observableArray property to your object, using aforementioned order at creation as initial value.

    Last thing is to bind cells order and text to new values:

    <table>
       <thead>  
         <tr data-bind="foreach:order">
           <td data-bind="text:$root.headers[$data]"></td>
        </tr>
     </thead>
      <tbody data-bind="foreach:users">   
        <tr data-bind="foreach:$root.order">
            <td><span data-bind="text:$parent[$data]"></span></td>
        </tr>
      </tbody>
    </table>
    

    Info about $root and $parent.

    With current approach you can change columns order dynamically by code like this:

    model.order(["name", "last", "age", "middle"])
    

    Example here: http://jsfiddle.net/Klaster_1/Pw2VE/1/

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

Sidebar

Related Questions

I am using knockout.js & knockout.validation plugins. I am adding the example fiddle http://jsfiddle.net/hsnCW/1/
Let's suppose we have a DOM tree: <div id=rootNode> <span data-bind=... > </span> <div>
With Knockout 2.0 using this data-bind: data-bind=click: $root.deleteSomeEntity.bind($data, $parent) in the Knockout viewmodel JavaScript
I'm using knockout in the following manner successfully: <div id=Options data-bind=foreach: Options> <button type=button
I'm using knockout to set the background image on some divs: <div class=values data-bind=foreach:
I am trying to populate Select using knockout data-bind option for a list of
I'm using knockout.js and twitter bootstrap's modal plugin to data-bind the user's email address
I am using knockout and have an array Properties and each Property can have
I just started using knockout.js and it works great with normal bidings. I have
I am using knockout on one of my page. I have a list of

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.