Comments (7)
Hey @mzanrosso,
Thank you for opening the issue.
As I understand you basically have a structure with a huge list of fields and you need to rename them correct?
You could use a Format
modifier to achieve this. though it would be as convenient.
I could create an util function for this I ?hope?.
Didn't test it but it got to work I guess.
fn change_header(table: &mut Table, mut data: Vec<String>) -> &mut Table {
table.with(Modify::new(Row(..1)).with(|s: &str| {
match data.pop() {
Some(new_s) => s,
None => s.to_string(),
}
}))
}
from tabled.
The following example works.
fn main() {
let data = [
["Hello World", "123123123231"],
["Hello World", "zxczczxcxczxczxc"],
["Hello World", "[[[[[[[[[[[[[[[[["],
];
let mut table = Table::new(&data).with(Style::github_markdown());
let headers = vec!["HEADER_1".to_string(), "HEADER_2".to_string()];
let count_columns = <[&str; 2] as Tabled>::headers().len();
for i in 0..count_columns {
let header = headers[i].clone();
table = table.with(Modify::new(tabled::Cell(0, i)).with(move |_: &str| header.clone()));
}
println!("{}", table);
}
Overall I agree we need better way.
I'll tackle it tommorow.
Good night! :)
from tabled.
@zhiburt - Thanks for the answer. Yeah I saw that with some trick you can achieve this result but it's not the simplest and the smartest way to do it, since I need to replicate this code a lot of times, this header change has to be one line maximum.
from tabled.
I've added a FormatFrom
which you can use.
Lines 36 to 40 in b10b0d3
But after a good sleep I kind of started to think you may better follow another approach.
Could you show actually how you compose your structure?
from tabled.
I was just wondering if a #[header(inline)]
help you?
from tabled.
Hey @zhiburt thanks for the examples; even if I think it can be more clean and simple, this is fair enough for my use-case:
println!(
"{}",
Table::new(testtable)
.with(Modify::new(Row(0..1)).with(FormatFrom(vec![
"test1", "test2", "test3", "test4", "test5", "test6"
])))
.to_string()
);
from tabled.
Great.
even if I think it can be more clean and simple,
I've done that in such way because it can be used in a more broad list of cases.
Could you show your vision on how it would be more simple and clean?
As you showed here?
println!("{}", Table::new(testtable).with_headers(headers).to_string());
And ones again could you show your data structure? 😄
I just tend to think that #[header(inline)]
is a good fit in your case.
from tabled.
Related Issues (20)
- Unicode width not being accounted for HOT 2
- Can it be integrated with leptos? Can you give an example? HOT 4
- Add per column alignment setting for `ColumnNames`
- Typo in lib.rs line 72 - "almoust" should be "almost" HOT 1
- Is there any way to cut short long row entries HOT 3
- reduce padding option?
- Possible way to set intersection to a different character for just one row/column? HOT 3
- Make all set functions for `Style` `const` HOT 1
- `table.is_empty()` on tables with only a header row HOT 3
- Question: Is there a way to conditionally apply a cell background color? HOT 5
- Impossible to call `Style::empty().remove_left()` HOT 8
- `Rotate::Bottom` must reorder rows?
- Refactor `Builder` methods HOT 17
- Add a indent size
- Does not build on MacOS HOT 4
- Add a benchmark to compare against a basic tabulation HOT 1
- Why the left/right border does not have intersection `CompactTable`
- Impl `Dimension` for Vec<usize>
- Add a `skip` function to `CompactTable`
- Create a iterative interface to `CompactTable`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tabled.