What is the method for presenting an integer column from a specific table to a user on the front end as a series that automatically increments from 1?

I'm currently developing a comprehensive full-stack application designed to function as a task and project management tool. It features a table layout with a convenient drag and drop functionality that enables upper-management to easily re-prioritize tasks and projects. The interface presented to upper-management is as follows:

 -----------------------------------------
|Priority| Task                 | Resource|
 -----------------------------------------
|    1   | Write some code      | Arya S. |
 -----------------------------------------
|    2   | Write a spec.        | Bran S. |
 -----------------------------------------
|    3   | Write some code      | Bran S. |
 -----------------------------------------

...and so on for over 100 tasks. Each assigned resource has the ability to log in and view only their designated tasks. For example, if Bran logs in:

 -----------------------------------------
|Priority| Task                 | Resource|
 -----------------------------------------
|    2   | Write a spec.        | Bran S. |
 -----------------------------------------
|    3   | Write some code      | Bran S. |
 -----------------------------------------

The priority column corresponds to a column in our SQL Server database. I am looking for a way to utilize SQL to adjust the priority (either through the middle-tier JAVA code or using a SQL view) so that 'Bran S.' sees his priorities starting from 1. The desired outcome would be:

 -----------------------------------------
|Priority| Task                 | Resource|
 -----------------------------------------
|    1   | Write a spec.        | Bran S. |
 -----------------------------------------
|    2   | Write some code      | Bran S. |
 -----------------------------------------

I am hoping to avoid using JQuery/DOM manipulation as it can be inefficient and result in a complex system with numerous interconnected components. Any recommendations or guidance on how to achieve this objective would be highly appreciated!

Answer №1

Utilizing Row_Number() in SQL Server can be quite helpful for this scenario.

For instance:

 Select [Priority] = row_number() over (partition by [resouce] order by [Priority])
       ,[Task]
       ,[Resouce]
  From  YourTable

Keep in mind: In cases of conflicting priorities, you have the option to substitute row_number() with dense_rank()

To perform updates on your table...

;with cte as (
 Select *
       ,[NewPriority] = row_number() over (partition by [resouce] order by [Priority])
  From  YourTable
)
Update cte set [Priority]=[NewPriority]

Answer №2

To incorporate row_number() function into your code, make sure to include it in either the procedure or select command you are working on.

snippet

        create table #tempTable
        (
        Priority int identity(1,1),
            Task    varchar(100),
            Resource varchar(100)
            )

        insert into  #tempTable
        select    'Create a new feature' ,'Jon S.' UNION 
        select  'Design a prototype'  ,'Daenerys Targaryen' union 
        select 'Fix a bug ' ,'Tyrion Lannister'

        select * from #tempTable

        select ROW_NUMBER() over (order by Priority),Task,  Resource
        from    #tempTable

        delete from #tempTable
        where Priority = 1

        select  ROW_NUMBER() over (order by Priority) Priority,Task,    Resource
        from    #tempTable

        drop table #tempTable

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A method for replacing keys within an object with those from another object

I am looking for a way to remove keys from objects within another object using TypeScript. let before = { '0': { 'title':'title 1', 'time':'12.30pm', }, '1': { 'title&apos ...

Having difficulty displaying GLTF object using three.js

I am attempting to display a GLTF object provided by the guidance from three.js (https://github.com/mrdoob/three.js/blob/master/examples/models/gltf/DamagedHelmet) In order to achieve this, I have used the loader mentioned in their documentation () Follo ...

Stop the default drag behavior on an input range element in VueJS

Is there a way to disable the default drag functionality of an input range element without affecting the click feature? Users should be able to change values by clicking instead of dragging. <input type="range" min="0" max=& ...

Running a server-side function on the client-side in Node.js

I am currently working with the following code snippet on the server: var game = io.listen(app); game.sockets.on('connection', function(socket){ storePlayers(socket.id); //Only the player who connects receives this message socket.em ...

Steps for accessing the "this" keyword within the parent function

Struggling with referencing `this` within a parent function while building a basic tab system using AngularJS. It seems like I may not have a solid grasp on the fundamentals, so any guidance would be appreciated: JavaScript: $scope.tabs = { _this: th ...

Using two different Readable streams to pipe to the same Writable stream multiple times

In my current project, I am facing the challenge of concatenating a string and a Readable stream. The Readable stream is linked to a file that may contain data in multiple chunks, making it quite large. My objective is to combine these two entities into on ...

Utilizing Vue and Prismic rich text: incorporating an event listener onto a span element

In my Vue app, I am retrieving content from Prismic using an API CMS. Within this content, there are certain sections enclosed in span tags with a unique class. My goal is to target those specific span nodes in Vue and apply an event listener to them. Whe ...

Efficient Ways to Present and Personalize Indian Date and Time using JavaScript

Hey there, currently creating my website and need some assistance. I'm looking to display the date and time in different sections of the page. Having some trouble with getting Indian time to work properly using PHP. If you could help me out with Ja ...

Ensuring the authenticity of a Node.js model through the utilization of

Recently, I've been working on developing a NodeJS application using JavaScript and MySQL. As the object I'm handling started to grow in complexity making it difficult to read, I received a recommendation to implement the builder pattern. In resp ...

Did you know about the Java advanced for loop and how it can help prevent

Why am I encountering the IndexOutOfBoundsException error while using Java enhanced for loop? Here is my code snippet: for (WebElement input : driver.findElements(By.cssSelector("input[type='text']"))) { if (input.isDisplayed()) { in ...

The DeepL API encounters issues when translating lengthy passages of text

While working with the DeepL API for text translation, everything was running smoothly until I encountered an issue. If the text to be translated exceeds 4000 characters, the API returns an error status without actually translating the data. https://api.de ...

The toFixed() function seems to only be giving back values ending in

The issue I'm facing is that the code below is only returning decimal places with values like .00, even when the set values are supposed to be .67, 1.33, 2.67, etc. $(function($) { $('#CourseMenu select').change(function() { var ...

Concealing jQueryUI tooltip upon clicking a "target=_blank" link

I have implemented jQuery to display tooltips for all links on my webpage that include a 'details' attribute. $(function() { $tooltip = $(document).tooltip({ show: false, track: true, ...

Different choice when utilizing Attribute="Value" in jQuery

When the button is clicked, my goal is to hide all elements and show only the Divs with the name attribute equal to the id of the button. I already know how to achieve this by getting elements by ID, but since I need multiple elements with unique IDs, or b ...

Using jQuery's ajax function to send data with a variable name of data field

I am trying to figure out how to dynamically add a variable to the name of the data field I want to send information to through ajax. Below is an example of the code I'm working on: var qty = $('#qty_'+value).val(); $.ajax({ url: &apo ...

What is the process for creating a stored procedure that extracts and stores the final column data into a table?

My table includes the last column as a code. Here's what the table looks like: Rule_ID Simple_English_Description Source_Attribute Dependent_Attribute View text ------------------------------------------------------------------------------- ...

Enable only the current week days on the multiple date picker feature

Can anyone recommend a date picker that only shows the current week and allows for multiple date selections by the user? I found this jsfiddle which limits the display to the current week, but it doesn't support selecting multiple dates. I attempted ...

Tips for restricting function invocations in JavaScript?

I am seeking a function called limitCalls(fn, maxCalls) which accepts a function fn and creates a new function that can only be called the specified number of times in maxCalls. Here is a test example: it('limitCalls', () => { const makeIncre ...

Utilizing ng-repeat Loop Variable in ng-include Content within Angular Framework

I am looking to create two tables with identical record structures. One table will serve as the Main table, while the other will act as an Archive. Each record is represented by bootstrap divs with col-sm-x structure containing details such as {{rec.Name}} ...

Sorting strings in arrays using Bubble Sort in either descending or ascending order

Sorting strings in an array has been causing a bit of trouble for me. I expected my code to produce two different outputs, but I'm only getting the output in ascending order. import java.util.*; public class nextLineArray1 { public static vo ...