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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:22:08+00:00 2026-06-12T16:22:08+00:00

I have recently used a great stack overflow answer by RP Niemeyer, KnockoutJS ObservableArray

  • 0

I have recently used a great stack overflow answer by RP Niemeyer, KnockoutJS ObservableArray data grouping, to allow me to group data in an observableArray by a field. That is working brilliantly. The problem is it is not playing nicely with Knockout Sortable. There is a problem with retrieving the sourceParent. Please see the following fiddle: http://jsfiddle.net/mrfunnel/g6rbc

Basically I have one nested list where tasks are grouped into routes (unscheduled) and another list of just tasks (scheduled). I want to be able to drag routes and tasks into scheduled. If a route is dragged in it needs to split up into tasks.

Any assistance would be greatly appreciated.

  • 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-12T16:22:09+00:00Added an answer on June 12, 2026 at 4:22 pm

    The sortable binding only works against observableArrays, because it needs to know how to write the dropped value back to the array. With the result of a computed observable, it would not be able to write it in a meaningful way.

    Here is an alternative way that you might be able to structure your code. Basically, you would build an observableArray of routes that each contain an observableArray of tasks. Something like:

    self.tasks.subscribe(function(tasks) {
        var routes = [],
            routeIndex = {};
    
        ko.utils.arrayForEach(tasks || [], function(task) {
           var routeId = task.routeId(),
               routeTasks = routeIndex[routeId];
    
           //first time that we have seen this routeID
           if (!routeTasks) {
               //add it to the index, so we can find it without looping next time 
               routeIndex[routeId] = routeTasks = { id: routeId, tasks: ko.observableArray() };
               //add it to the array that we will eventually return
               routes.push(routeTasks);
           }
    
           routeTasks.tasks.push(task);
        });
    
        //return an array of routes that each contain an array of tasks
        self.tasksByRoute(routes);       
    
    });
    

    Then, you can use the beforeMove callback on your scheduled tasks to check if it is a route rather than an individual task and do the splitting like:

    self.myDropCallback = function(arg) {
        var spliceArgs;
        //determine if this is really a route rather than an individual task
        if (arg.item && arg.item.tasks) {
           //we will handle the drop ourselves, since we have to split into tasks
           arg.cancelDrop = true;
    
            //build up args, since first two need to be new index and items to remove
           spliceArgs = [arg.targetIndex, null];
           //add the tasks to the args
           spliceArgs.push.apply(spliceArgs, arg.item.tasks());
           //splice in the tasks at the right index
           arg.targetParent.splice.apply(arg.targetParent, spliceArgs); 
    
           //remove the originals, after cancel has happened
           setTimeout(function() {
              arg.sourceParent.remove(arg.item);    
           }, 0);                
        }
    };
    

    Here is an updated sample: http://jsfiddle.net/rniemeyer/BeZ2c/. I am not sure if you allow sorting between the routes, but I disabled that in the sample. You can drop individual tasks or entire routes into the scheduled tasks.

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

Sidebar

Related Questions

I have recently started using R and am still getting used to its data
I have recently used an icon file received from our marketing team. The icon
I have recently used a PHP pagination tutorial, Pagination - what it is and
I have recently started a project in Ruby on Rails. I used to do
Recently, I have worked in a project were TDD (Test Driven Development) was used.
I recently switched to command-line git for my personal projects. I have used 3-way
I have recently used modified a word count method in javascript for my website,
I have used the following code several times before, and have recently found it
How to design a latest recently used cache? Suppose that you have visited some
I have recently discovered Spring project for MVC testing: spring-test-mvc . It's a great

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.