I need to filter data based on the number of rows and columns provided by the user.
After reading an excel file, I extract the data in the controller:
https://i.sstatic.net/vPpxL.png
These are the column headers retrieved after the user entered 5 as the input columns: https://i.sstatic.net/n05OZ.png
Here is the row data obtained when the user specified 4 rows to be displayed, containing data for 4 rows: https://i.sstatic.net/4FT9y.png
In each row, there are key-value pairs consisting of the column name and cell value:
https://i.sstatic.net/XDDKJ.png
I aim to filter this row data based on the header names received through columns, ensuring each row only contains values up to the defined column. Currently, I receive all values within a row.
Even though I've attempted some logic, it's not functioning properly.
var rowData=[];
for(var i=0;i<headerNames.length;i++){//headerNames holds column names
for(var j=0;j<data.length;j++){//data includes row data
for(var keyName in data[j])
if(angular.equals(keyName,headerNames[i])){
rowData.push({'keyName':data[j][keyName]})//I want to match only key-values with column names. Although I intend to set the keyName value as the array key, it's currently coming as keyName:18
}
}
}
}
Linking the code plunker. http://plnkr.co/edit/28Z44xDBug7nFCQnFCQJL?p=preview
I successfully filter data on the UI to display only the specified row and column data by the user. However, I also need to filter this data on the controller to save it in MongoDB. The goal is to trim the row data according to the column input so that only values up to that column are retained in the array. In my current code, I'm struggling to correctly set the key value as the array key.
Please advise on how to efficiently filter and splice the row values so that each row only contains values up to the specified column numbers. For example, if a user enters 4 rows and 5 columns, I should retain only values up to the 5th column in my row Data array, discarding all other values. As of now, I can't extract the key value to assign it as the array key.
Your assistance in resolving this issue would be greatly appreciated.