cancel
Showing results for 
Search instead for 
Did you mean: 

create and display table columns on weekly basis based on rows

ganeshbabu_kd
Explorer
0 Kudos

Hello all,

Thanks in advance for replying my post.

we have one example scenario, that we need to display table columns with week number and that based on date value in the table rows (note: the date value will see only we can bind rows on table).

Will anyone has tried attempted this situation or any instruction please suggest to us.

Thanks..

Accepted Solutions (1)

Accepted Solutions (1)

ganeshbabu_kd
Explorer
0 Kudos

Hi All.

Thanks for your comments.

I have rearranging my question.i will get the start week and end week columns from the input field.

will it be possible to displaying those 2 records in the table with corresponding week column

(ie.. i have <valuestartdate> and <valueenddate>, should i need to find weeknumber for those two dates and loads the values to between week numbers columns on table).

My input xml like as..

Start week - 01    and end week 52  ( will get it from input field)

<entity>

<firstname>Suresh </firstname>

<lastname> Kumar </lastname>

<valuestartdate>20140101<valuestartdate>

<valueenddate>20140228</valueenddate>

<values>30</values>

<emailid>sureshkumar@mail.com</emailid>

</entity>

<entity>

<firstname>harish </firstname>

<lastname> Kumar </lastname>

<valuestartdate>20140301<valuestartdate>

<valueenddate>20140410</valueenddate>

<values>70</values>

<emailid>harishkumar@gmail.com</emailid>

</entity>

The output table like this..

Cheers

Ganesh

Qualiture
Active Contributor
0 Kudos

Yup, could easily be done, and even a bit simpler than what I mentioned earlier:


  • You know the start and end dates, so you should be able to calculate the week numbers of this date range (you could use Dennis Seah's provided formula for that)
  • Since that weeknumber range could be dynamic, it's best to store it in a model and use that as a column aggregation  Create a table with 1-53 weeknumber columns (yes, there are years with 53 weeks)
  • Since you know the weeknumbers, simply store the value for each weeknumber in your model
  • Bind that to your table's row aggregation

With all these hints, you should be perfectly able to develop your requirements

ganeshbabu_kd
Explorer
0 Kudos

Hi,

Thanks Robin :).

If possible means. could you please share required sap.ui.table code for comparison of week number columns with the xml values.

Cheers.

Ganesh

Qualiture
Active Contributor
0 Kudos

The calculation of week numbers were already given by Dennis in his jsbin example :


jQuery(function() {

  // this getWeek function is gotten from

  // http://techblog.procurios.nl/k/news/view/33796/14863/calculate-iso-8601-week-and-year-in-javascript....

  Date.prototype.getWeek = function () {

    var target  = new Date(this.valueOf());  

    var dayNr   = (this.getDay() + 6) % 7;

    target.setDate(target.getDate() - dayNr + 3);

    var firstThursday = target.valueOf();

    target.setMonth(0, 1);

    if (target.getDay() != 4) {

      target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);

    }

    return 1 + Math.ceil((firstThursday - target) / 604800000); // 604800000 = 7 * 24 * 3600 * 1000

  }

and you call it using :


var d = Date.parse(<your xml date>);

var weekNr = new Date(d).getWeek();

ganeshbabu_kd
Explorer
0 Kudos

Hi,

Thanks a lot Robin

As i can able to finding week number of my XML dates from the getWeek();  function, now how i can map the week number values to columns weeks.

ie. if my starting week numbe values from xml is "01" and my end week number values are "09" means that how will load my <values> 30 </values> to all required week number columns.

do we have any jquery function to map all required week columns in that values ?.

Possibly you can share any of the sample sap.ui.table codes. it will more helps me.

Cheers

Ganesh

Qualiture
Active Contributor
0 Kudos

The code I'll leave up to you, since that's fairly easy

You need to take a step back, and think about how your table model should look like.

Now, since you know the columns, and the data it should represent, you already know how your model should look like:


var tableModel = [

    {

        firstName : "Suresh",

        lastName  : "Kumar",

        email     : "sureshkumar@mail.com",

        week01    : 30,

        week02    : 30,

        //etc, repeat for week03 to week09

        week09    : 30

    },

    {

        firstName : "Harish",

        lastName  : "Kumar",

        email     : "harishkumar@mail.com",

        week09    : 60,

        week10    : 60,

        //etc, repeat for week11 to week 15

        week15    : 60

    },

    ...

]

The fun part is in creating this model; you need to iterate through your XML data, and build up the array with the calculated week numbers for your start/enddates.

I'll leave it as an exercise for you how to build this table model array since that's just plain old JavaScript

ganeshbabu_kd
Explorer
0 Kudos

Hi Robin,

Your input helps me. Thanks a lot for solving my issue.

-Ganesh

Answers (2)

Answers (2)

former_member182862
Active Contributor
0 Kudos

HI Ganesh

Maybe this is what you want?

Example

-D

ganeshbabu_kd
Explorer
0 Kudos

Hi

.

Thanks for your reply.

am giving my exact requirement here.. My xml inputs are

<firstname>Suresh </firstname>

<lastname> Kumar </lastname>

<startdate>20140101<startdate>

<enddate>20140322</enddate>

<values>30</values>

<emailid>sureshkumar@mail.com</emailid>

those start date and end date, i need to split on weekly basis and display the value(30) in all week columns.

ie. my required output should like..

Firstname Lastname Email_id                     week1 week2 week3 week4 week5 week6.... week12

Suresh     Kumar     sureshkumar@mail.com 30      30      30      30       30       30      ....  30

if possible can you share the any example will prepare table columns and rows like this.

Cheers

Ganesh

Qualiture
Active Contributor
0 Kudos

I don't quite understand your requirement:

  1. do you need to convert dates in your model to weeknumbers, and have these displayed as table columns (so if you have 5 dates in your model, you would see at most 5 columns with weeknumbers)

    or

  2. do you need a table with columns 1-52 and have the model data displayed under the respective weeknumber column?

I may sound like a broken record, but without any more details and/or code to show where your got stuck it's pretty impossible to help -

ganeshbabu_kd
Explorer
0 Kudos

Hi Robin.

Thanks for your reply.

am giving my exact requirement here.. My xml inputs are

<firstname>Suresh </firstname>

<lastname> Kumar </lastname>

<startdate>20140101<startdate>

<enddate>20140322</enddate>

<values>30</values>

<emailid>sureshkumar@mail.com</emailid>

those start date and end date, i need to split on weekly basis and display the value(30) in all week columns.

ie. my required output should like..

Firstname Lastname Email_id                     week1 week2 week3 week4 week5 week6.... week12

Suresh     Kumar     sureshkumar@mail.com 30      30      30      30       30       30      ....  30

if possible can you share the any example will prepare table columns and rows like this.

Cheers

Ganesh

Qualiture
Active Contributor
0 Kudos

Just take a step back and think about what you need :

  • You know the start and end dates, so you should be able to calculate the week numbers of this date range (you could use Dennis Seah's provided formula for that)
  • Since that weeknumber range could be dynamic, it's best to store it in a model and use that as a column aggregation
  • Since you know the weeknumbers, simply store the value for each weeknumber in your model
  • Bind that to your table

Have fun coding!

former_member182862
Active Contributor
0 Kudos

HI Robin

Yes, the challenge is that the columns appear to be dynamic. Look like we need to parse the data once to figure out the begin and end weeks. If we get more data (presume that we can scroll down and get more rows) then columns needs to be recomputed. 😞

Yeah, Have fun coding 🙂

-D